Android moving back to first activity on button click

后端 未结 6 2201
情歌与酒
情歌与酒 2020-12-03 07:14

I am writing a application where I am dealing with 4 activities, let\'s say A, B, C & D. Activity A invokes B, B invokes C, C invokes D. On each of the activity, I have

6条回答
  •  广开言路
    2020-12-03 07:43

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(D.this, A.class));
        }
    });
    

    Declare A in your manifest with the android:launchMode="singleTask". This way, when you call startActivity() from your other activies, and A is already running, it will just bring it to the front. Otherwise it'll launch a new instance.

提交回复
热议问题