Android – back button to close two activities?

Solved!

My activity stack looks like this, forgive the rough chart!

A-->B-->C-->D

If I press the back button in activity B, I will return to a as expected. However, if I press the back button in activity C or D, I will return to a instead of B. in my opinion, this may be caused by two things: 1) activity B exits when opening the intention of C or D; 2) the back button is invoked twice in some way?

I carefully studied the click listeners in activity B, which started the intention of expecting to find a finish () call there, but I didn't. I also checked the onbackpressed () method of activities C and D to see if I opened activity a manually... But I didn't

This is the onresume method of activity a

protected void onResume() {
        super.onResume();
        screenOn(SCREEN_ON_DURATION);
        mWakeLock.acquire();

    }

This is the way I began to intend C and D

            Bundle info = new Bundle(); 
            info.putString("classId", ""+classId );


            Intent intent = new Intent(Notebook.this, StudentChooser.class);
            intent.putExtras(info); 

            Notebook.this.startActivity(intent);

Can I help you?

Editor: I found finish () in onuserleavehint (), which is the problem!

resolvent:

The reason may be that you are using finish() in your prevIoUs activity,For example
A->B->C
            Intent intent = new Intent(B.this, C.class);
            startActivity(intent);
            finish();

finish() is destroying B activity hence the control is going on activity A on back button
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>