If you don't care about the last opened activity, then call finish
on each activity just after you call startActivity
calling the next one.
If you do care, and just want to kill'em all when you click the Exit button on the last activity, then use BroadcastReceivers
:
- Create a
BaseActivity
like this:
public class BaseActivity extends Activity {
private KillReceiver mKillReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mKillReceiver = new KillReceiver();
registerReceiver(mKillReceiver,
IntentFilter.create("kill", "spartan!!!"));
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mKillReceiver);
}
private final class KillReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
finish();
}
}
}
- Make your activities extend that
BaseActivity
.
- Whenever you want to clear the stack:
Intent intent = new Intent("kill");
intent.setType("spartan!!!");
sendBroadcast(intent);