Cannot simulate process death - android

I am trying to simulate "Process Death" in my Android Studio and have done the following steps:
Changed Background process limit in emulator
Test app has Application class, MainActivity and Activity2 with just layout. Run the app and open Activity2.
Press home button and open more than 5 other apps.
Check attatch to debugger and no process exists.
Go to the emulator and open the app from recent app menu.
I expected I would see the Activity2 but the app starts thorugh normal process and I was able to the application class started and MainActivity only shown.
Am I missing something to reproduce process death? Quite confused with this.
Thanks in advance with your help.

Related

Is an application terminated when I close all activities?

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!

Android Studio Stop Button not Stopping

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

Issue when application is running in background

I am facing an absolutely abnormal problem in my android application.Scenario is like that:-
I have a main activity in which a button is placed named as SOS .On long press the button,another activity is launched in which a timer starts.
The timer is executed in a service so that it can be easily runs in background also. Now the timer is running and when i pressed the home button of the device the app goes in background.Till now its fine.Now the problem is that when I again launch the application by clicking the application icon.The timer is not visible.
The application starts again from scratch.but the timer is still running in the background.What I want that,the same screen should be reopened when the application is launched again that is Timer screen.Now this problem is not arises when I deploy the build from the eclipse.Everything is working fine in this case.
But when I deploy the build in the device after downloading from the mail account,the above problem arises.
Please help me to sort out this problem.
Hope you know the behavior of Android OS,
When your Activity is in background and OS need to free some memory it will kill your app and start it again when you need.
If everything is right in your logic then might be your app being terminated by OS.

How to gracefully terminate an app on Android emulator with Eclipse (on Mac)

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

Why has the Eclipse Debugger/Emulator disconnected from my app?

My app is no longer starting up automatically when I F11 it in Eclipse; the Emulator starts up, but I then have to go and find my app among the applications list/array to invoke it.
Then, when I get to the place in my app where I've set a breakpoint, instead of hitting the breakpoint (Eclipse is not even going into Debug Perspective), my app suddenly "expires" and the Emulator pops up the dialog:
~~~~~~~~~~~~~~~~~~~~~~~~~
Sorry!
The application FifeOrTheDinosaur (process.com.aXX3AndSpace.FifeOrTheDinosaur_Package) has stopped unexpectedly. Please try again.
Force close
~~~~~~~~~~~~~~~~~~~~~~~~~
But then when I click "Force Close," that dialog goes away, and my app starts up again, from its opening Activity...?!?
It's almost as if my app is not the one being debugged by Eclipse -- Eclipse has lost its connection to it or...???
And every time it crashed, I hit the "Force Close" button, whereupon my app starts up all over again. What could have disconnected my app from the Debugging system, so that it:
1) Doesn't run automatically when I run it; rather, I have to "force" it to start up, and when it enters a breakpoint, Eclipse's Debug Perspective is not invoked
2) Continually starts up my app after it has failed...???
I put a breakpoint on a button click handler prior to that one that is working fine, and it does not drop me into the Eclipse debugger, either...???
Update:
The console says:
1) ] Failed to install .apk on device 'emulator-5554': timeout
2) Launch canceled!
Updated 3/30/2012:
If I run the app from Eclipse and immediately shut it down just as the Emulator is starting to initialize, it flashes up three "command window"-type screens, one right after the other, too fast to read what text they contain. Normally the Emulator window simply goes away, so I don't know if this is a clue for anybody as to what might be happening...
That sounds like the normal behavior of android Apps. If one activity crashes you can still go back to the activity the App started with. And if the breakpoints aren't hit then the error might occure before the code line you want to stop at.
Maybe you could set a breakpoint before you change the activity and then debug from there on.
You could also provide your Log output. Errors like that can always happen if you forgot to declare permissions or activities in your Android Manifest.

Categories

Resources