Hello everyone and have a nice day!

I wrote an application that determines my location and sends data to the database. When you minimize the application on the On Pause On Stop life cycles, I wrote a method that also forces the application to determine its location and send them to the database. There are no problems, I checked everything through the logs. How correct it is or not is another question. So, the application opens in OnCreate , there is a button that, when pressed, starts the cycle and makes the button invisible, but if you minimize and expand the application, the button is visible. Why???

    1 answer 1

    When folding, the principles of the жизненного цикла Activity .

    Once your database is already working, create a table for storing settings, in which there will be a field for the state of the required button and just one row. Hide the button, set (update) in the database, for example, false ( boolean field) or 0 ( int field). Before showing in onCreate check the value in the database. If true ( boolean field) or 1 ( int field) shows a button, if false - do not show. So you can store the desired state of the application without the Bundle and SharedPreference .

    • I use the remote Mysql database and I’m not entirely clear about your idea. Could you not show it more correctly or with any obvious example - elik
    • well you somehow work from a DB? there are tables there, you create them, make queries, insert, update. Or I do not understand that with the database you are all right? - TimurVI
    • Yes, I did not understand that you will create a table and one bulin line will set it to false by default and then you don’t know what to do and how to check it) - elik
    • Create a method that climbs into the database in the desired table, check if the desired value is there and return it via this method. - TimurVI
    • one
      in any case, you need to let the Activity know when to show something, and when not to show something, right? - TimurVI