I have an activity 'A' defined in Manifest like below:
<activity
android:name=".A"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I launch my APP, that activity is always loaded from the start. It wont start from my prev activity.
When I remove android:launchMode, then it works as I expect.
Since you set android:launchMode="singleTask", the activity A will always be the root of your activities.
From DOCS:
In contrast, "singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.
Default mode is standard. So, when you remove android:launchMode="singleTask", your APP returns to standard launch mode.
That's why if you app is always starting Activity A.
If you would like to start a different Activity on launch replace that in the xml name attribute that contains LAUNCHER
<activity
android:name=".ActivityB"
android:launchMode="singleTask"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Where Activity B is an alternate activity.
Related
Possible Duplicate Deep linking and multiple app instances. I have implemented Deep Linking in my app. I have Splash activity that is launcher and MainActivity that handles the Intent as defined in manifest:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#drawable/app_logo"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/AppTheme">
<activity
android:name=".ActivitySplash"
android:configChanges="orientation|screenSize"
android:label="#string/app_name">
<intent-filter>
<!-- Launcher activity -->
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ActivityMain"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|screenSize"
android:exported="true"
android:label="#string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.mywebsite.com"
android:pathPrefix="/something"
android:scheme="http" />
</intent-filter>
</activity>
<activity
android:name=".ActivitySignIn"
android:configChanges="screenSize|orientation" />
<activity android:name=".ActivitySignUp" />
</application>
I have set launch mode singleTask to handle onNewIntent(). Now what i want to achieve is that if user opens activity from DeepLinking and there is already some task going on in MainActivity I prompt user a dialog either he want to cancel current task and start new task (which is from deep linking). The issue is If i open another activity from MainActivity and user comes from DeepLinking Intent. Then it would kill the second activity and directly open MainActivity. What i want to achieve is that if app/activity is not running then Intent from DeepLink open as is. And if activity/app is already running then i prompt user to either close current task and perform DeepLink task/intent.
This doesn't really work the way you think it does. You are trying to use launchMode="singleTask", but since you haven't also set "taskAffinity", Android pretty much ignores your launchMode.
You should not need to use either of the special launch modes "singleTask" or "singleInstance" to get what you want.
Try using singleTop launch mode and see if this solves your problem. If ActivityMain is already open and you launch ActivityMain again using your deep-link, onNewIntent() should be called in ActivityMain.
You can also look at my answer to this question which describes a way to determine what Activity to show based on using a static variable to decide whether another Activity is in the stack or not.
I've combined two apks. One of them runs only on background. So I thought that It must have been easy to do. But I have a problem. After I install my signed apk I see two of them on the menu. Why are they seperated? How can I make them run together? Here is the activity part which causes the problem.
<activity android:label="#string/app_name" android:name=".MainActivity" android:theme="#android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:configChanges="orientation" android:label="#string/app_name" android:name=".FreeMemoryRecover">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
You're defining both of them as launcher activities, which is a perfectly legitimate thing to do, just not what you want. Define only one as a launcher activity, and have it launch the other in a new task.
Note that you cannot launch an activity into the background, only launch an activity over the current one. And there is no guarantee that an activity will continue to exist once it's in the background or even in the backstack of the same task. It sounds like you should convert one of your activities to a Service.
Scenario:
Two Activities being shown in launcher for one app, they have different taskAffinities because I was getting the problem of when I open one, hit home, open the other, the first one would be opened. So, I added taskAffinity in the AndroidManifest for the proper tasks.
The problem I'm getting is that if I open one, hit home, hit the second one, it will open the proper task/Activity, BUT I have to click on the icon twice in order for it to open and get, this ONLY happens with the activity that specifies a taskAffinity, the other one opens just fine on the first click every time.
731-1337/? W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#4e640b6 attribute=null, token = android.os.BinderProxy#3edac0ca
Here is the manifest
<activity
android:name=".firstActivity"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".secondActivity"
android:label="#string/second_activity"
android:icon="#drawable/ic_second_activity"
android:taskAffinity="secondTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".thirdActivity"
android:label="#string/second_activity"
android:taskAffinity="secondTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"/>
I fixed this by adding this to the thirdActivty which was being called by secondActivity immediately on launch.
android:launchMode="singleTask"
So it ended up looking like
<activity android:name=".thirdActivity"
android:label="#string/second_activity"
android:taskAffinity="secondTask"
android:launchMode="singleTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"/>
Hope someone finds this solution helpful.
I have an activity called "MainActivity", this is my main activity which declared in the manifest file as launcher:
<activity
android:name="com.example.tester.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
The VOICE_COMMAND works only one time and then nothing is happen.
I have tried to separate it into 2 activities: 1 activity is the main and the other is associated with the VOICE_COMMAND intent filter, and still, the application works only once.
If it's separated into 2 activities it works fine only when the application starts immediately from the launcher, but if the application starts from the second activity (with the VOICE_COMMAND intent filter) it works only once.
Any suggestion?
Thank you
I have found the answer:
Setting the attribute:
android:launchMode="singleTask"
and it works fine.
Thank you
I have two activities namely login and calendar in my Application. Currently my startup activity is "calendar". I want to run the login as first activity not calendar.
The startup activity [Launcher Activity] is declared in the projects' AndroidManifest.xml file
Look for that activity tag in the manifest which looks like this
<activity android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.
That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.
Add Intent filter to the Activity in which you want startup.
In your case Modify the AndroidManifest.xml file as follows
<activity android:name=".login"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
remove the intent-filter code from calendar Activity tag in manifest and add it to the Activity you wanna load first
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I mean paste it in the activity you like to run as default.
<activity
android:name="com.example.gridviewimages.AnotherActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Where as
From the docs
category -- Gives additional information about the action to execute. For example,
CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while
CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can
perform on a piece of data.
MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
You want the Application element of the Android Manifest file. You can see details here.
Look at the name attribute, this points to the Application class.