Posts

Showing posts from March, 2022

Content Providers - Consuming data from a Content Provider using Content Resolver

Content Providers are used to share data between applications When is it necessary to implement Content Provider? When we have to expose our apps data with other app Need some complex data copy functionality from our app We intend to use :  Cursor Loader Cursor Adapter AbstractThreadedSyncAdapter What kind of data can Content Provider Expose? Data from Database FIle Data(JSON, XML, Audio, Video, Photos) Networked Data - AbstractThreadedSyncAdapter How to implement Content Provider? We need to make sure we have primary keys defined in our tables else Content Providers will not work properly Implement Custom ContentProvider class Define proper Content URIs for data to be exposed Content URI? Is an important concept to access any data from a ContentProvider.  Assuming we are sharing data from database : Content URI has 3 components : Content : content:// Authority : Package Name of the App Path : User Defined String Constants Suppose App2 needs some data from App1 App2 will use a...

Fragment Implementation

How fragment will inform the activity of any events? We need to use the callback interface for fragment interaction through the activity. While coming to implementations, its nothing but the callback interface with a method. interface CallbackInterface {      callbackMethod() } The activity is going to implement this particular interface as a part of it, it has to give the implementation of the callback method that is available in the callback interface Activity implements CallbackInterface {     callbackMethod() - implementation } So who will invoke this particular method? The fragments will be invoking this method. The fragments will have a instance of the CallbackInterface when the fragment is created.  How can we pass data from an Activity to Fragment? In Activity, we need to do the following : fragment.setArguement(Bundle) In Fragment , we can get the data by calling : Bundle = Fragment.getArguements() public class MainActivity extends AppCompatActivit...

Fragments Basic Knowledge

Image
Fragment Lifecycle : The Correlation between Activity and Fragment Lifecycle considering Fragment is created on creation of Activity OnCreate - A onAttach - F onCreate - F onCreateView - F onActivityCreated - F onStart - F onStart - A onResume - A onResume - F onPause - F onPause - A onStop - F onStop - A onDestroyView - F onDestroy - F onDetach - F onDestroy - A The Correlation between Activity and Fragment Lifecycle considering Activity is created 1st and then the fragment is added OnCreate - A onStart - A onResume - A onAttach - F onCreate - F onCreateView - F onActivityCreated - F onStart - F onResume - F onPause - F onPause - A onStop - F onStop - A onDestroyView - F onDestroy - F onDetach - F onDestroy - A The Correlation between Activity and Fragment Lifecycle considering Activity is created 1st and then the fragment is added to back   stack and back pressed OnCreate - A onStart - A onResume - A onAttach - F onCreate - F onCreateView - F onActivityCreated - F onStart - F on...