I have 3 activity tasks A-B-C
<activity android:name=".LoginActivity"
android:label="#string/app_name"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".DashboardActivity"
android:label="#string/app_name" >
</activity>
<activity android:name=".CreateNewPolygonActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboard|keyboardHidden">
</activity>
<service android:name=".services.RecordCircuitService"
android:enabled="true" >
</service>
And I have a Service with GPS using LocationManager.
My application has this logic:
On launcher icon clicked - > start login activity
After login - > login activity is finish(); and start dashboardActivity
In the dashboard I start CreateNewPolygonActivity and start the Service with GPS
Press HOME (this is reorganize RecordActivity to foreground)
after I have some mistakes work
open CreateNewPolygonActivity with onCreate
open DashboardActivity
I think I have a problem with my task organization.
You won't achieve the desired result by setting launchMode="singleTask" for your activity. Android won't create a separate task for this because you've not set the taskAffinity. In any case, you don't want to do this by using launchMode="singleTask" because this causes more problems than it solves. This launch mode is intended for HOME-screen replacements only!
Remove launchMode="singleTask"`` fromCreateNewPolygonActivity`
Also, you should remove android:noHistory="true" from your login activity. This isn't necessary either. Since you've already finished the login activity when the user starts the DashboardActivity, when he presses the BACK button, it won't return to the login activity (which I assume is what you wanted).
Once you've done these things, please tell us what is still broken.
Related
I Have the Code in manifest:
<activity android:name=".activities.login.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.main.screen.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
What is happening:
The i load the app for the first time (Ex: Install it from
androidStudio) 'MainActivity' is loaded but once i close and launch
again LoginActivity is launched everytime
This happens for the first time
MainActivity launching happening for the first time
Its should always load 'LoginActivity' right since my launcher is
'LoginActivity' why is LoginActivity loaded just for first time. Is
there any setting i need to check
You have used
android:launchMode="singleTop"
in your main activity. According to docs -
if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.
So that's why MainActivity is loading.
You should remove
android:launchMode="singleTop"
to get desired results.
For more information on launch modes refer docs -
https://developer.android.com/guide/topics/manifest/activity-element
I have two applications installed on my device, application A and application B.
When a user launches application A, they press a button to launch application B.
I use the following code:
Intent intent = Global.CurrentContext.getPackageManager().getLaunchIntentForPackage("some.random.app");
Global.CurrentContext.startActivity(intent);
The first time the user does this, it works fine and works as expected, however, if the user then launches the phones task manager and swipes away application B. When the user then presses the button in application A. The activity is not created.
I believe this is something to do with the way that the task and the activity are being destroyed by android. My thought process is that when the user swipes to kill application B that the activity is destroyed, but the task remains. Then the second time they press the button in application A, that it's attaching to the old task and then not showing for the user.
Application A's activity manifest for the activity:
<activity
android:name="a.a.a.LogonActivity"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Light.NoTitleBar"
android:windowSoftInputMode="stateHidden"/>
Application B's activity manifest for the activity:
<activity
android:name=".activity.HomeActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I set android:noHistory="false", it works. I think it is android:noHistory="true" killed applicationA's top activity, makes it doesn't work.
I am developing an hybrid app using IBM worklight where I have to open another webview on the top of existing webview(Cordova webview),so i created a new activity(WebView Activity) to load my external page,but when i am going to background from webview activity by pressing home button and again coming to foreground my MainActivity getting called and restarts the app,I have used singleTop for my MainActivity in manifest file
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:launchMode="singleTop"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="com.main.sample.NOTIFICATION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".WebViewActivity"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:launchMode="singleTop"
android:theme="#style/Theme.Transparent">
</activity>
I don't know why it is happening,I want my last activity to get resumed instead of main activity
Read documentation for the modes.This will explain you about what is happening:
"singleTask" and "singleInstance", should be used only when the > activity has an ACTION_MAIN and a CATEGORY_LAUNCHER filter. > Imagine, for example, what could happen if the filter is missing: An > intent launches a "singleTask" activity, initiating a new task, and > the user spends some time working in that task. The user then presses > the Home button. The task is now sent to the background and is not > visible. Now the user has no way to return to the task, because it is > not represented in the application launcher.
This is one potential solution.There are multiple ways to do this.
Try using the following code in the onCreate method of the activity that is specified as the Launcher Activity in the Manifest:
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
finish();
return;
}
This will finish your Launcher Activity before it is displayed by detecting that there is already a task running, and your app should instead resume to the last visible Activity.
So I have an Activity A that is defined in the AndroidManifest.xml as defined below:
<activity
android:name=".activity.A"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This Activity launches a welcome Screen which we will call Activity B.
If you launch the application the Welcome screen is displayed and then once the user is done with it Activity A comes back.
The issue I am having is when I push the "Home" button from the welcome screen I go back to the Home Screen as expected. Now when I reclick on the Application Icon the application won't launch. Instead both my Activity A & B get destroyed. If I click on the icon again then the application relaunches as expected.
Now if I'm on the welcome screen and push the back arrow and reclick on the App icon it launches the application as expected. I don't have to push it twice.
Unfortunately I have to use the launchMode="singleTask" since it is a requirement for integration with another team. I have read the Android API's for Tasks and Back Stacks numerous times. Any pointers or suggestions would be greatly appreciated.
I came across a blog indicating there is an undocumented bug with using singleTask and intent-filters together but didn't find any official documentation on this.
Thanks
EDIT
Launching Activity B like this:
Intent intent = new Intent(context, B.class);
startActivityForResult(intent, CONST_VAR);
I tried making two activities which launches ActivityB from Activity A. I see no such problem as described in the question. PFB my manifest. Also, when you say home button, is it Phone home button or your app specific home button. PFB my manifest
<activity
android:name="com.android.testsingletask.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.android.testsingletask.WelcomeActivity"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
android:label="#string/app_name" >
</activity>
I am in trouble, I want to start my application from starting every time but it's not being.
When I exit from my application & come again. I found same activity which I have left before exit.
Now If I **shut down or switch off** my Android Device direct when my application is in foreground & then I **switch on device again**. I get same activity which I have left earlier. But I want to fresh application from login page. Because my setter & getter is null after switch on device, and I found all value null in my application.
My Manifest file is below:
<activity
android:name=".Main"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".screens.ScreenSplash"
android:screenOrientation="portrait" />
<activity android:name=".screens.LoginActivity" />
<activity
android:name=".screens.LoginActivity"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".screens.MainMenu"
android:configChanges="orientation|keyboardHidden" />
Kindly help me which is the problem & what should I do. Any help would be appreciated.
Add to your activity manifest
android:clearTaskOnLaunch="true"
According to your Manifest .Main is the launcher activity. so when your application is launched from icon tap then this is the first activity to display and rather if your application is not having any other activity on top of the stack.
so if you want to see the fresh login activity then make the login activity as launcher activity.
Maybe you want to try setting launchMode to standard?
http://developer.android.com/guide/topics/manifest/activity-element.html