Firstly close in an android application is frowned upon because the back button and home button are already kinda giving you this functionality.
But if you need to you can do this
When the user wishes to exit all open activities, they should press a button which loads the first Activity that runs when your app starts.
Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
The above code clears all the activities except for first activity. Then put this code inside the first activity's onCreate()
, to signal when it should self destruct when the 'Exit' message is passed.
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…