Do not keep activities

    Do not save operations

    “Do not keep operations” - the phrase “Do not keep activities” in Android settings is translated in such a strange way. And the description “Delete all operations immediately after their completion by the user” does not add clarity. It is included in the menu "Developer Options" (Developer Options), located at the very bottom.

    This setting works very simply, when it is turned on, all inactive activities die. Those. after the transition from activity A to activity B, activity A is destroyed. Thus, you can check how your application fits into the activity lifecycle .

    I do not want to go into the details of the lifecycle, but, in a nutshell, the system kills the background activity when it wants. In reality, this is not so rare, so do not neglect it. For example, someone called you. During your conversation, the system may kill the activity of the application that you just used.

    Or, the easiest way to kill activity is to rotate the screen (if not android: configChanges = "keyboardHidden | orientation | screenSize"). But not all applications support screen rotation. And those who support, encounter lifecycle errors at the development stage, so they just should not have problems. The second easy way is to change the language of the device.
    Well, of course you can just turn on “Do not keep activities”.

    I spent several days fixing bugs after I went through my application with “Do not keep activities”. Now, I think it’s always worth turning this setting on during development. My main problem was the correct connection of social networks in the application.

    There were almost no problems with Vkontakte, with their SDK you can write everything correctly, but still they have a small problem. Namely, after authorization through the application, the result is returned to onActivityResult. According to the documentation, you need to call
    VKUIHelper.onActivityResult(requestCode, resultCode, data);

    however, in the case of the destruction of the activity of our application, NPE will crash, so you must first call

    Not entirely obvious, and undocumented. Started issue, just in case.

    There were problems with Facebook, because, by my own stupidity, I decided to use android-simple-facebook, and its author, as I understand it, was not really worried about the android lifecycle. I had to completely abandon it and redo everything on the official Facebook SDK and all the problems were gone. Although, probably, it was possible to correct everything with one line, but there was no turning back.

    And there were absolutely no problems with Twitter, because everything works just like an ax. They simply do not have their SDK and authorization through the application. We have to do everything the old fashioned way, through WebView. In general, they have the most terrible authorization of all.
    Well yes it is, a digression.

    There are problems with the PayPal SDK, it just crashes wherever possible. Fortunately, someone has already brought the issue to me, and they will probably fix it in the near future.

    Other examples

    I don’t have many applications on the phone, and to be honest I’m too lazy to watch them, but I couldn’t get past the recently released habr application. Let's start, of course, with him. Well, I’ll add a Payoneer error that I accidentally found :)


    I stumbled across different screens and was already upset, was everything written correctly and I alone made so many mistakes. But no, I did get to the About page:

    Caused by: java.lang.NullPointerException
           at ru.habrahabr.activity.about.AboutFragment.onAttach(


    It didn’t take much time. Login screen, went to keepass for the password, returned - gypsum crash:

    Caused by: java.lang.NullPointerException

    There are still some applications without crashes, but with incorrect behavior, for example, the open fragment is not saved, and instead, after re-creation, the main application screen is displayed again.


    Use the “Do not keep activities” setting, I hope for someone this information will be new and will help to avoid behavior errors and crash.
    I think I could also avoid a bunch of reports on Google Play if I knew about this setting right away.

    Oh yes, I sent reports.

    Also popular now: