Reputation: 67
I have an app in which i have three activity namely:- Login,MainActivity and password activity.when I go to password activity and do some event then after login activity comes and here when i press back it will remove login and Mainactivity comes which I don't want. what i want when i press device back twice it will simple close app not to come Mainactivity.How can I archeive this problem.
code that i have tried but not success.
Login code:-
@Override
protected void onResume() {
super.onResume();
clearAllTask();
}
private void clearAllTask() {
CMainActivity m_MainActivity = new CMainActivity();
if (m_MainActivity.m_MainActivity != null) {
m_MainActivity.m_MainActivity.finish();
}
}
and code for MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m_MainActivity = this;
}
Upvotes: 0
Views: 1172
Reputation: 299
You need to clear the back-stack where you are using the Intent
Like this:
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
Here FirstActivity
will get cleared from back-stack and will be finished. Also you will be navigated to SecondActivity
. So when you press back button from SecondActivity
, it will close the app.
Hope this will solve your problem.
Upvotes: 2