Friday, 4 September 2015

5.What are Activities in Android ?

As I told that in Android we are just dealing with Activities. Every Screen having content or not is an Activity.


Whether it is the home screen of your device or First or Last Screen of your Application is an Activity.(Its just introduction, Things will be more clear Don't worry about that).

Now back to flow, in our first application, 
The class MainActiity.java is representing an Activity as you can see it is extending a class AppCompatActivity.java (as sytex says class MainActivity extends Activity).

Now in previous versions of android we were dealing with Activity class instead of AppCompatActivity.
As time passes new things are added so android has many resources to be added so they have made new class AppComatActivity which contains so many features which the previous class did not.

Now we are Overriding (see "@Override" its syntex to override methods) three methods, I mentioned in previous post.

Now understanding all three methods
1. onCreate(Bundle savedInstanceState)
We can say that this method builds the Activity when Activity starts for the very first time and also rebuilds Activity when Application is out of memory. Take this example, If you are working on application, and a moment comes when you have to check out other applications something like that then, If application gets out of the memory then the Activity on which you were working has to be rebuilt and also when orientation changes and the prior data(Last data like last user edits) must remains so the Activity continues with its last state.

The (Bundle SavedIntanceState) stores or roles the prior Datas and fills into Activity again when Activity gets rebuild.

It will be too sooner to think about next twos (This is what I think so I will proceed with that two methods later).

So we are dealing with the first method onCreate only we would use other methods very later sections.

No comments:

Post a Comment