Reputation: 160
Very good, I am delighted with this great forum. I managed to solve almost all my doubts on.
But now I have a question that I can not solve.
In my app I have a set drawerLayout. Works perfectly, but I want put down the list button to exit the app. I had thought about doing that when you had clicked "Exit", open a Fragment with the following code:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
SalirFragment.this.getActivity().finish();
return super.onCreateView(inflater, container, savedInstanceState);
}
But this code is causing the app to close when opened.
Anyone have any suggestions? Thank you very much to all
Upvotes: 0
Views: 308
Reputation: 1973
to close all the previous activities.There some changes have to be made in the application
onclick of button start the activity that starts when you launch the application and which is there in activity stack. Like below.
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("Exit me", true);
startActivity(intent);
finish();
Then in that activity lets say "MainActivity" onCreate() method add this to finish the MainActivity
setContentView(R.layout.main_layout);
if( getIntent().getBooleanExtra("Exit me", false)){
finish();
return; // add this to prevent from doing unnecessary stuffs
}
Upvotes: 2