Android: Launch app from app installer will cause several instances? - android

1.install an apk from app installer
2.then just click "OPEN" to launch it at once
3.after the app launched and then press HOME key
4.find the app from app list and click its icon to launch again
5.then the app will be launched with a new instance.
And if you repeat 3~5 several times, it will repeat create a new instance. if you press "BACK" key now, you will see the app is still there for the same times you launched.
But if you just click "DONE" at step 2 and then launch the app from app list, everything will be OK then.
Why?

The app installer (as well as many Android IDEs) use different intent flags than the regular app launcher does, which means that the launcher's intent doesn't properly match with the Activity's existing intent and it ends up creating a new activity on top of the stack.
I think this question is similar to what you're asking about:
Activity stack ordering problem when launching application from Android app installer and from Home screen

Related

Issue between app as the shortcut and app in the menu

I have a problem were I launch my app go to a different activity and press home. If I press the app again it starts with the activity I recently went to. However, this only works depending on where I originally launched the app. If I use the shortcut version of my app on the home screen and go to another activity then press home and then go to the app menu version where my app is located, I get sent to the main activity and not from the activity I recently went to. Is there any solutions to this?

No launcher icon but still able to be opened

I have got an app that is using "plugin apps" (apps without launcher icon that get started via intent by the main application) and i want to have the Play Store "Open"-Button for this application to just open the main application.
Is there a way of not having the launcher icon but defining an entry point in order to launch the main application after play store install (by intent or launching a dummy activity which will launch the other applications activity immediatly).
I thought about removing the launcher category "android.intent.category.LAUNCHER" and still setting the main action "android.intent.action.MAIN". But this seems not to work at least via apk install the "Open" button is not active.
Thanks
You could try android.intent.category.INFO.
According to the documentation, this is for the case where you want to provide an entry activity for your app, but don't want your app to be shown in the app list.

I have two app icons in Recent Applications , how to avoid?

I have two activities in "Recent Applications". For those that don't know, Recent Applications is when you long press the home button.
I know why this happens. I am starting my app from a BroadCastIntentReceiver. Then I start my app from the normal launcher icon.
When I press the first icon in Recent Applications, the app opens from the Main activity. However, when I press the second icon, the app opens from the place where the BroadCastIntentReceiver starts the app, this is called PictureActivity.
I have been looking into taskAffinity and am having trouble deciding the most simple way to solve this issue.
Thank you!
When your BroadCastIntentReceiver builds its intent to launch the PictureActivity, try setting this flag on the intent:
intent.addFlags( Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS );
Reference: Android dev site.

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.

Why does not Android retain application state after pressing Home button if application is ran first tyme from App Manager?

Steps to reproduce the problem.
Create or dowload any application with several activities.
Load apk file to sdcard or install from market.
Install appliaction using standard App Manager.
After installation in App Manager press Open or press on notification message after downloading.
After application running go to the next (the second) application screen.
Press HOME.
Press application icon.
What happened.
Appliaction is restarting from the first screen and does not retain the second screen.
Application retains activites in normal way after application restart or if you pressing BACK button in application to home screen.
Correct behavior should be.
Application must always retain activites in normal way.
How can I solve this problem for my application?
Can I restart application during first run?
Depending on how the application is defined in the manifest file and whether it has any mechanism to save and restore its state....
Based on your steps, it might create several instances of the same application (check this)
Or it is not using the instance Bunble in onCreate
It is definitely not going to be automatic for all applications to come back to the save screen it was at when it was paused or destroyed (some application do not want that, think about your bank account management...)
Edit :
So if I understand correctly from your comments, it works as you expect when you quit the application with the BACK key, but not when you use the HOME key...
Read the link I posted : http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html
You will understand that when you press the HOME key, the instance of your application you were in is not destroyed (and so the current state is not saved). Starting it again only starts another instance (from the initial screen).
When the user presses the BACK key,
the current activity is destroyed and
the previous activity resumes.
...
A task is a cohesive unit that can
move to the "background" when users
begin a new task or go to the Home
screen, via the HOME key
If you want to change the way it behaves, look at the launchMode in the manifest.
I think that App Manager runs my application in wrong way. It runs my applications in its task. When I press HOME and press application icon I runs second task with my application.
I tested it. I made two applications App1, App2. App2 has two activities A and B.
App1 runs App2 in the simplest way.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("org.app2.test", "org.app2.test.Screen1"));
Test 1. Run App1. App1 runs App2 activity A. Acctivity A runs activity B.
Press Home. Press App2 icon. You can see App2 activity A.
That I changed code for launching App2.
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName("org.app2.test", "org.app2.test.Screen1"));
Test 2. Run App1. App1 runs App2 activity A. Acctivity A runs activity B.
Press Home. Press App2 icon. You can see App2 activity B.

Categories

Resources