I am working on a minimal open-source Launcher (wikipedia) for Android.
When I run it on a phone, put that on standby and unlock it after 4 - 6 hours, all I get is a black screen.
I hope this has some general solution and is not only caused by my code.
That way answers to this question will also be useful to everyone else on here.
Relevant mentions for my code
In the Android Manifest XML I declared the main activity to be a launcher (home screen). The main activity (MainActivity.kt) has an onCreate function, only refreshes a clock and checks for some OnTouch events. The full project code can also be seen on GitHub.
Go to the related issue on Github.
You should try implementing onResume() if you haven't already. It is possible that the app has not stopped and as such onStart() would not be called when you unlock your phone.
Where an app has paused, it would just call onResume() instead. You can try putting your code here to recreate the views as needed. You can also save any relevant user information in onPause() and reload it in onResume(). This will allow you to preserve a consistent user experience and avoid memory leaks caused by, for example, referring to objects that no longer exist.
Let me know if it works, good luck.
The Activity Lifecycle
Related
I'm developing a android 2D game in android studio.
I have a problem with my activity Lifecycle.
My question is this:
I have 2 activities. One named LauncherActivity, and the other named MainActivity.
When I first launch the app, the LauncherActivity launches, and everything works just fine.Then, when I go the the MainAcitivty, which is the activity that hold my game, meaning that it has the line : setContentView(new GameController(this)), everything still works fine. Then when I go back to the launcher activity, everything still works fine, but NOW when I'm trying to go back to the game, the MainActivity, in the second time, then the Lifecycle is as follow:
onCreate(),onStart(),onResume(),onPause(),onStop(),onResume().
This is ruining all my game, because I have specific things in my onStop() method, which I can not allow them to be executed when the activity launch.
Does someone know how to fix this ? What am I doing wrong ?
If I was not clear, please ask me and I will explain.
Android call onStop when the activity is no longer visible. Please review document. https://developer.android.com/guide/components/activities/activity-lifecycle.html
I hope it can help you.
I need to know how to keep the user (child in this case) from accidentally hitting the home button and others closing the app. I want a parent to be able to hand the baby the phone and as she/he taps it will make sounds. That's all. My little one is my beta tester and she keeps closing it unintentionally then getting mad. I'm using android studio with ics+ support.
Although it is possible by overriding the onPause() method, or relaunching the app when closed, both shown here.
I would recommend checking if the phone is running 5.0 or higher. If it is, then show how to use screen pinning, which requires the overview and back buttons to be held together for 5 seconds - something which a small child is unlikely to do.
The company I started working for recently gave me their current Android project to read and understand. I am having a really hard time which activity starts or intends to start which one, basically not being able to understand the flow of things (Apart from the launcher activity)
Is there an easier way to determine the activity flow of the application apart from searching for Intent calls in every file, each file being large no. of lines of code?
Can you build and run the app so you can see and feel what different screens do?
Find main activity in a manifest. Search in main activity startActivity() or startActivityForResult(), navigate to the next one and so on. This way you can draw graph, you may try any scripting language to automate the process.
The project may have fragments, so you will have to find FragmentManager and commit().
In my application there is a scenario in which all the variables in the app get cleared when I get incoming call while using my app. I think the Android OsS is collecting the garbage to make free space.
But this makes my app working weird. There are nearly 30 static variables used in my app which are all get cleared. Any suggestion to not get cleared.
Thanks.
Problems like this occur, if you do not correctly implement the activity life cycle. In particular you have to override onSaveInstanceState() if you have data that should be preserved when your activity is stopped.
Please have a look at the official activity guide for more details.
I have been developing Android application that use Activity with "download" button and Service for executing downloading in the background. And I have following task: to show message about downloading if application is currently displayed. How can I detect it? Is there standard Android OS functions for it? Thank you.
You can do this at the activity level, not for the application as a whole. Check out the description of the activity lifecycle. (Also see "Managing the Activity Lifecycle" in the Activities framework topic.) When your activity becomes visible, the framework will call it's onStart() method. When the user can interact with the activity, the framework will call the onResume() method. You can override one of these to know when your activity is showing or actually interacting with the user.
Note that, as described in the documentation, things work a little differently starting in Honeycomb (3.0).
The basic method is to use Broadcast receiver to share information between a service and an application. If your requirement is to update the status/progress of download on the main activity, you can use it.
Here is a simple tutorial about how to share information between a service and an activity. You can update the progress of download. It works for the activity that is currently running.
To check for it as the activity starts, you should override the onCreate, onStart() or onResume() functions.
Also there is a very neat solution presented in another question and i recommend that you should try to use that. It involves extending the Application class to store the information, and use its instance to check for updates. See this