![]() In the second activity I just wanted to show two fragments which I just created above, so in its layout file, I will add the two fragments. ![]() public class MainActivity extends AppCompatActivity ![]() StartActivity(new Intent(MainActivity.this, SecondActivity.class)) package androidhunger.activityfragmentintentdemo import. What is interesting is that Fragments have their own lifecycle and thus provide us with an independent way of working without having to rely on activities that much. SO for example if you need one main page with sub-pages, then you need to think about Fragments. In MainActivity I just initialize the button and set a click listener to it to call SecondActivity, this moving from one activity to another activity here is done using an Intent. A single activity can host multiple fragments. Below is a simple application which has one button in one activity and when clicked to goes to other activity using intent and in the other activity, two fragments are shown. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |