This is one workaround I tried and it worked fine for me.
SOLUTION-1
this.finish();//try activityname.finish instead of this
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
use this in the action in which you want to exit the application.
==================================================== ================================= The above code helps to resume your application where you last stayed.
SOLUTION-2
, , .
onActivityResult()
, , 3 A, B, C, A- > B- > C, C , .
A
public class A extends Activity {
int Finish = 100;
Button launch_second;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
launch_second = (Button) findViewById(R.id.start_second_act);
launch_second.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent second = new Intent(A.this,
B.class);
startActivityForResult(second, Finish);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 100:
this.finish();
break;
default:
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
B
public class B extends Activity {
private Button launch_next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_main);
launch_next = (Button) findViewById(R.id.start_third_activity);
launch_next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent third = new Intent(B.this,C.class);
startActivityForResult(third, 100);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 100:
setResult(requestCode);
this.finish();
break;
default:
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
C
public class C extends Activity {
Button kill_app;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third_main);
kill_app = (Button)findViewById(R.id.kill_app_btn);
kill_app.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
C.this.finish();
setResult(100);
}
});
}
}
-3
finishAffinity(), , .