preface

GIF images depict the problem

Problems in the process

My page ==> My Settings ==> Log out In fact, this log out is to return to the login page. If the customer clicks back again, it will exit the app. Then the problem is that if the customer clicks back again, the app will have a black screen and restart the app

demand

My page ==> My Settings ==> Log out In fact, this log out is to return to the login page. If the customer clicks back again, he will log out of the APP. Do not black screen and do not appear on my page

The solution

1. The use of the System. The exit (0); Because I didn’t add collection Cause this method cannot be used 2. Android. OS) Process. The killProcess (android. OS. Process. MyPid ()); 3. EventBus solved the problem

code

I should end the main screen after I’ve logged out of my Settings screen

private void logoutSuccess() { ToastUtils.showShort(getActivity(), R.string.logout_success); UserUtils.cleanLogin(); startActivity(new Intent(getActivity(), LoginActivity.class)); if (getActivity() ! = null) getActivity().finish(); Eventbus.getdefault ().post(new MessageEvent(" Exit successfully ")); }Copy the code

Turn off MainActivity on my main page after receiving a message from EventBus

@Subscribe(threadMode = ThreadMode.MAIN) public void Event(MessageEvent messageEvent) { if (messageEvent.obj.equals(" Exit successfully ")) MainActivity.this.finish(); }Copy the code

Finally, don’t forget to cancel the registration of EventBus, and the renderings will not be uploaded. Perfect solution to the black screen caused by the failure to exit the Android APP, or when you press the back button again, it will return to my page.

I want to work my way up

Fly forward on the blades at the highest point

Let the wind blow dry tears and sweat

I want to work my way up

Waiting for the sun to watch its face

Little days have big dreams

I have my day

Let the wind blow dry tears and sweat

One day I will have my day