Android – return without pressing the back button

In AActivity, press button1 and call BActivity..

Button b1= (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(AActivity.this, BActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});

In bactivity, I want to press button 2 and recall aativity

Button b2= (Button)findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//How to do?
}
});

I want to come back without pressing the back button on the keyboard. And replace it with a button in the layout. What should I do?

Can the oncreate () method be run when calling back aaactivity?

resolvent:

Only you must complete the activity by calling the finish () method

Sample code

Button b2= (Button)findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

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
分享
二维码
< <上一篇
下一篇>>