I'm using my phone to debug and test my application through android studio. When I hit run on the android studio the application lunches correctly. When I hit the back button on my phone, even though the application seems to close, I don't get an application terminated message on my android studio run log and the red stop button on anroid studio is still clickable. The application is just an empty test application.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The same thing happens if I use finish() to terminate the application through code. I would like to know if this is normal behavior for an android application or if I'm doing something wrong. Why does the android studio process remain on? Has my app terminated properly or am I leaving unterminated applications on the memory this way?
When I hit the back button on my phone, even though the application seems to close, I don't get an application terminated message on my android studio run log and the red stop button on anroid studio is still clickable
I do not know what "an application terminated message" means. Pressing BACK will destroy an activity (by default). It has no immediate effect on your process, which is what the red stop button in Android Studio is tied to.
I would like to know if this is normal behavior for an android application or if I'm doing something wrong
This is normal behavior.
Why does the android studio process remain on?
The red stop button is enabled because the process is still running. Android will terminate the process when Android decides to do so, usually because it is running low on system RAM.
am I leaving unterminated applications on the memory this way?
Yes. This is by design. The user might elect to return to your app fairly quickly, in which case it is more efficient to just start a fresh activity in your existing process than would be to start a process, then start an activity in that process.
It is a normal behaviour.
As Android system manages background tasks on it's own when you exit your app by pressing back button, your app's process is is still running in background in case you might need to get back to it. But if you do not get back to your app it's instance is destroyed by the OS after some time.
It is a normal behaviour on Android Studio!
Related
In Android when you hold down the home button you can bring up a task list of your recent apps. And each "card" in the task list should have a preview of the app. However, this time I opened the task list and the previews were blank (except for the app title).
I had the phone Settings in the task list and every time I would tap on the task and try to open it in would close immediately.
I also had this app I was developing and when I tapped on the task to open the app my RecyclerView wasn't showing anything, when it should be.
I also was playing AngryBirds 2, so was it that Android had silently killed those apps for memory? If so, does onCreate() of the killed apps get called again when this happens?
Edit: I just noticed if you close an app too quickly when it's transitioning to an Activity you can get a blank preview.
Edit 2: So to answer my question, after referencing the Activity lifecycle diagram this is what I found. When another application needs memory, the app's process will be killed and when the user navigates back to the app, onCreate() will be called again. However, that doesn't explain why I couldn't reopen the Settings. And I have no idea how to reproduce this weird behavior!
Ok after some debugging, I found out that Android did indeed kill my app because it needed memory. When you resume to your app however, onCreate will be called with a savedInstanceState that is NOT null. I had some logic that required savedInstanceState to be null and therefore my RecyclerView wasn't populated.
To recreate this scenario of Android killing my app I had to open a ton of apps lol. Is there way I can reproduce Android killing my app without opening all those apps? Hm...
This has to be a dumb question, but in Android Studio 0.3.2 I'm attempting to stop my app at a particular spot so I can test a particular automatic resume feature the next time I restart the app (to imitate a failure). However, when I hit the stop button in the debugger, it just disconnects and the app keeps on running. Am I misunderstanding what the stop button does? Is there any way to legitimately kill the app from the debugger like you can for iOS apps in XCode?
The stop button simply disconnects the debugger from your device.
To accomplish what you are trying to test you will have to press the home button which will go through the activity life cycle until onStop(). When you open your app again it will onStart() then onResume().
If you need more assistance just let me know.
Android Studio and Android uses different approach than Xcode and iOS
Android Studio stops debugger instead of application that is why you should manage application/activity/fragment lifecycle on OS level. For example you can open another app or press home button or navigate to another screen
I am trying to end my app gracefully on an Android emulator without causing a crash or killing the app.
Having read numerous posts on how to terminate or crash an app on Android, here's what I've tried:
Switched the emulator to another app
Clicked the Hang up on call button and Make a call button on the emulator
Added finish(); System.exit(0); to my onPause event in the app
Clicked on the root of my program in the Debug perspective in Eclipse and clicked the red square on the menu icon row to terminate, did same and disconnected as well.
Each time I start up the app after any of the above, the tracking code is considering the above chosen method a crash.
So I'm trying to figure out how to gracefully end my app and restart it without incurring a 'crash'.
Any ideas?
Big thanks
I have written a simple database program in android. It runs fine, there is no force close error. But I checked from my application from Settings App I see the Force Close option enabled, which implies that my application is still running in the background, even though I have completely came out from my application to the home screen by pressing back key. And moreover I am not using any services, alarm or broadcast things.
Can some one please guide me what may be the probable reason?. Or is it okay? Or will it crash if I put it on device?
Can some one please guide me what may be the probable reason?. Or is it okay? Or will it crash if I put it on device?
Your application is alive until Android OS needs more memory and destroys it. What I have understood does Android start destroying activities before killing the whole application. This means that your application can be alive even if you have finished your activities.
Do not worry about this; Android OS is handling this extremely well.
I am basically looking for the same functionality found in the DevTools (Development.apk) app that comes with the emulator. I am wanting to perform similar testing on an actual device but the DevTools app does not work properly on the device I have so I cannot use it.
I am looking to test in a similar way.
What this does is causes each Activity to be destroyed whenever it leaves the screen, holding onto its instance state just as if the system needed resources and had killed it. (So I can't just call finish)
Is there a way to do this?
Thanks
You can kill your app's process at any time using the DDMS stop button. highlight your application in the list and click the stop sign button. your application will be destroyed like it was killed by the system.
See the stop button in the left pane(Devices) above each device listing: