Android SDK onCreate problem - android

I think I've gotten myself seriously confused. Up until recently my app was working great. I hadn't changed anything except updated java and android tools. I'm not sure if that caused my problem or what, that's all I can remember changing related to it.
Here's the problem I'm running into, which just started.
Debug mode (installed app on phone through Eclipse):
Tap app icon to open app, onCreate is called
Hit home button, state is saved
Tap app icon to open app, it resumes, onCreate is not called
That worked, my app is happy.
Now I export the signed and zip aligned app, remove the app on my phone, install the new one, and repeat these steps:
Tap app icon to open app, onCreate is called
Hit home button, state is saved
Tap app icon to open app, onCreate is called again
Ugg, onCreate is called again? Bundle is null, my variables reset. This happens on the emulator too and for other users of the app. I can hold the home button down and switch to it and it continue where it left off but if I tap the icon it calls onCreate every single time.
Why is this happening? My app is a single activity.

Related

Home view is returned if I restore my app from apps icon android apk

When I run my apk directly in device without connecting the app to eclipse, and when I minimize my app such as pressing the home button -
if I press my app icon from opened app it will open the latest opened activity.
But if I press the icon of the app from app, the app run from the home activity.
I don't know the cause knowing that I don't override onpause or onstop or ondestroy method.
How can I resolve this issue?
Thank you

PhoneGap App state not saved on pause

When ever I export Android App(using a generated key store from eclipse) application state is not saved when running it. Say I am in 3rd screen, then if I go back to home and click on App drawer and launch it, it starts all over again. But if the app was installed from eclipse itself (through USB debugging) app behaves normally and state is saved.
Weird issue ! What might be causing this ? I checked developer options and activities are not getting killed as well on exit.

re-lunching an android app from list of recent apps vs pressing on the app icon

I have written an Android app that plays some audio. There is a stop button on the app GUI that when I first lunch the app works fine.
However when I go out of the app while audio is playing and come back depending on how I came back the STOP button works or not.
If I come back to the app by holding the home button and seeing the list of recent apps and choosing my app from there, then the STOP button works. But if I click on the app luncher icon the STOP button does not work.
What is the difference between these two method and how can I make the re-lunch of the app by pressing on the app icon to behave similar to when I re-lunch the app by choosing the app from the list of recent lunched apps.
Without seeing the code we can't be entirely sure, but it sounds like what is happening is that your activity is you set up an action listener (setOnClickListener) on your stop button in your onCreate() method.
The onCreate() doesn't get called again if the app is never recycled (Android will do this when your app is put into the background) and started over.
When your app is put into the background onPause() will get called, then coming back from that you will get a call to onResume(). If your app has been in the background longer or Android needed more resources you'll get a call to onStop hitting the home button and onStart when the app opens again.
You'll need to do some investigation into your code as to why your listener goes away, but now you have the hooks to make sure they are connected back up when you're app is back.

Android SDK onCreate called every single time

What am I missing here?
Problem is, I launch my app onCreate is called. I press the home button to leave it, press the app icon again and onCreate is called yet again. The activity is being killed, right? Well, if I press home to leave the app, hold down home, then pick the app from the running apps it resumes where I left off. So hitting home within the app is not killing the activity. Press the button to open the app is killing the activity.
I use Eclipse. I just downloaded the latest Eclipse and re-downloaded ADT and updated the Android SDK. Everything is up-to-date. I even uninstalled all java and downloaded and re-installed the latest jdk and runtime on my computer. Then re-signed the app.
Using Eclipse I added the skeleton sample project. Signed in debug mode and it resumes every single time, just like my real app. Signed for release and it has the problem: press home to leave the app, press the icon to launch the app and onCreate is called again. Literally every single time. Shouldn't it be resuming?
The problem is it's not just me (I have a BIONIC). It happens on other peoples phones and it happens on the emulator, but it only happens when signed for release. Signed for debug and it's perfectly fine.
Any ideas on this?
According to this previous question you need to set the FLAG_ACTIVITY_REORDER_TO_FRONT flag using setFlags(). This would cause your running activity to be reused instead of recreated every time an application starts it. When you press the icon on the home button, the activity is started. The home screen doesn't know if the application is running or not, so it just starts it. When you long press home, it actually switches to the activity as it knows it's running.
Another option seems to be setting android:launchMode to singleTop.

Signed apk does not keep the app in background

My issue is like this, I press home button and go to home page, then I press the app icon to get back to the app. Instead of resuming the app it starts from the beginning. But if I select app from recent app list, it resumes. So, some unknown reason app starts from the beginning if I press app icon.
I'm getting this strange result with signed apk. Unsigned/debug apk works fine, it resumes.
Please note that, I've not handled any BackStack activities, neither handled any activity android:launchMode.
At last I'm answering my own question. The issue is solved.
It turned out that Activity Standard LaunchMod (which is default settings) behaves like this in Some devices with OS v5.0 +. So, I added it to be "launchMode" in from menifest. So App works fine now. Although I'm still not sure about this behavior.

Categories

Resources