简体   繁体   中英

Switching between activities through Navigation Drawer

I have 2 activities which extend a base activity:

Class BaseActivity extends Activity
Class A extends BaseActivity
Class B extends BaseActivity

Now I have a button on A which allows the user to go to B , and a button on B which allows to go back to A .

So far, so good.
Now after reading this documentation, which is straightforward enough, I am implementing an additional activity between BaseActivity and A , B . The structure will be:

Class BaseActivity extends Activity
Class MyDrawer extends BaseActivity
Class A extends MyDrawer
Class B extends MyDrawer

The activity MyDrawer contains the code to use a Navigation Drawer. The problem I have is, I am not able to understand how do I use my Activities instead of Fragments in the Navigation Drawer. I want the users to be able to switch between activities through the drawer. Is this possible? or do I need to rewrite everything using Fragments instead of Activities?

Any help is appreciated.

Use intent's to switch between the activities. Refer to Navigation Drawer to switch between activities

public void selectItem(int position) {
Intent intent = null;
switch(position) {
    case 0:
        intent = new Intent(this, Activity_0.class);
        break;
    case 1:
        intent = new Intent(this, Activity_1.class);
        break;

    ...


    case 4: 
        intent = new Intent(this, Activity_4.class);
        break;

    default : 
        intent = new Intent(this, Activity_0.class); // Activity_0 as default
        break;
}

startActivity(intent);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM