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
Related
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 home button problem.
I have so many activities, when I press home buttom in any activities.
Then if I restart my app.
it started from splash activity(logo activity).
However, I want to start this from activity where I pressed home button.
Can anybody figure this out?
By default, Android handles this behavior. When you press the home button, the app should go to background and at the next time when you open it, it should start from where you left off. But, Android's memory management is designed to automatically terminate minimized apps that have not been accessed in a while when memory is needed for newly launched apps.
If there is enough memory available and still your app gets terminated, that means you are not using the API's correctly. Please read this [article] to know how to handle onPause() and onResume() to achieve this behavior.
Ok, I made an app for Android. And when we push the middle button or back(lefthandside) button of Android phone, we all know that Android apps still runs in the background.
So my code is this:
the first line(addEventListener) is in a private function which runs as soon as you open the app.
NativeApplication.nativeApplication.addEventListener(flash.events.Event.EXITING, onMyAppExit)
private function onMyAppExit(event:flash.events.Event):void{
trace("onMyAppExit is running");
saveProgress();
}
Basically, I want saveProgress() to run when the app ACTUALLY exits from running in the background. I noticed that my app actually exits when I open another app like Candy Crush. I guess the Android OS exits apps automatically when the apps are not being used and when the app you are using takes a lot of RAM. However, my code only works when I run my app in AIR Debug Launcher(Mobile). I know that because I see the trace in the function in my output window when I click on the x button on the right corner of the app window. But when I connect my Android phone to the computer and then ---> AIR3.8 for Android settings ---> Publish, and then I "Begin Remote Debug Session", and I open my app first, then open Candy Crush so that the Android OS automatically exits my app, I don't see the trace. So I finalized that the code didn't work on my phone.
I think you should use the event Event.DEACTIVATE,
when the app go to background you can save all so the os can kick your app off it's still safe :)
With that you have the event Event.ACTIVATE when the app go back on the foreground so you can handle it to revive your level.
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 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: