Today got problem that my apps cannot go Index activity always whenever I've already configured in manifest file.
<activity
android:name="com.ppshein.inm.IndexActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Problem is, I have two activities (index and detail).
1) open my apps, it go Index activity.
2) Click button in Index activity, then go Detail activity.
3) Click android "Home" button to exit in Detail activity.
(not click on android "back" button).
4) Once again open my apps, it automatically go to Detail activity (that's I don't want).
When I want is whenever I open my apps, always want to go Index activity first even close at Detail activity.
Nope, I've found the answer. The right answer is to add following attribute into the activity we want to set default as always.
android:clearTaskOnLaunch="true"
Related
I am building an Android application that launches 3rd party applications - both of which run in full screen.
When the 3rd party application is launched, if i swipe up from the bottom, i see the Android navigation bar (good) - however, if i then press the Android Home button on this nav bar, the 3rd party application exits (good), but my application is returned to the main boot activity and not the activity from which i launched the application from.
My application manifest contains..
<activity android:name=".boot.BootActivity"
android:configChanges="keyboardHidden|locale|layoutDirection"
android:excludeFromRecents="true"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
<activity android:name=".main.MainActivity"
android:configChanges="keyboardHidden|locale|layoutDirection"
android:label="#string/title_activity_main"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden" />
The BootActivity performs a bunch of pre-loading and model generation before waiting for the user to select a button which starts loading MainActivity which displays the menus and synopsis for the 3rd party apps.
When 3rd party is launched, we swipe up and press Home on the Android nav bar, the logcat is getting both "android.intent.action.MAIN" and "android.intent.category.HOME".
As mentioned above, this is causing the app to return to the boot activity - but i would like the 3rd party app to exit and return to the apps synopsis in MainActivity.
Can intent-filters be added, removed or temporarily disabled programmatically?
Generally using these special launch modes (singleTask) is a bad idea. If your BootActivity is launching HomeActivity, then this will not run in a new task, even though the launch mode would imply that, because these activities both have the same taskAffinity. If you really want to have them run in different tasks, then you need to set the taskAffinity of one or the other (or both) so that they are not the same. Read a bit about how taskAffinity works.
I want to know what is the differences between the back and up actions.
I've already found online how they work, but I didn't find what different happens when I trigger them.
When I intent another activity and go back with up action, it seems to just show again my last activity without executing any method (my images show like it was cached).
When I intent another activity and go back with back action, it seems to reconstruct the entire layout (my images reloads).
What really happens?
Thanks.
First you must understand the concept of Up and Back navigation, you should read this link about Navigation with UP and Back
When pressed back button the actual screen is removed but when pressed up button relaunch the parent-activity.
In your manifest need to add propert launchMode of activity, something like this
<activity
android:name="com.example.client.app.MainActivity"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I hope you serve.
My app consists of 2 activities:
<activity
android:name="com.domain.android.MainActivity"
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.domain.android.AboutActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I open my app, navigate to second screen, then go to the homescreen. From there I launch the app again - and it starts the main activity. But the app is running, it is just in the background, but why it didn't open the second activity? I guess it is something connected with activity's category. But how to fix that? Thanks.
Welcome to the ever-growing list of developers who have been bitten by this Android bug. Please see Re-launch of Activity on Home button, but...only the first time for all the gory details. And please go to Google Code and star the issues. We need all the noise we can make to get these fixed.
Hold your home button it will show the running apps click on your app it will open the activity from where you left. even if you click on the application launcher it will open the activity from where you left.
your application will not be in the same state sometimes if android needs resources it might end that activity. open an application move to next screen and press the home button and launch again it will open from where you left do the same with 5 or 6 apps then try launching the 1st app it will not be in the same state it will launch from the launch activity but any app you come to home screen and launch immediately it will open from where you left. If the background app is not doing anything android might end it if it needs resource. correct me if i am wrong. additional information i will be happy to know.
One issue may be that you have 2 activities designated as the main activity using:
<action android:name="android.intent.action.MAIN" />
You will probably have two icons in your launcher for your app. Each one will launch a different activity. You might be launching the first one again and again by using the icon for the first activity. Try removing
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
from your AboutActivity activity declaration. This might fix your problem.
I have the following problem:
When I press the Android HOME key, I can see the "Desktop" and my app icon. Then I press my app icon and my application launches twice. I don't want open my app twice.
How my program works:
I have 4 Activities (A, B, C, D).
A - The Main Activity: It is the first to open. It opens the other activity that has a lot of buttons. It's like a Java's main() method. I show a SplashScreen and I call another Activity. Then I finish my activity "A".
B - The Menu Screen: In this activity, I have some buttons, like a menu. I have a configuration button, update button, and Login Button. When I click the login button, I finish this activity and open the Login Screen (Activity "C").
C - The Login Screen: The user writes the Login and Password. If the login is successful, I finish this activity and open the Activity "D".
D - The application main screen: It stays opened all the time and launches another Activities. I finish this when I want close my application.
P.S.: I tried change the launchMode flag (androidManifest.xml), but didn't work.
My AndroidManifest.xml bellow:
<application android:label="#string/app_name" android:icon="#drawable/icon" android:name="MyApplication">
<activity android:name="A"
android:label="#string/app_name"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="br.com.site.B" android:label="#string/app_name" />
<activity android:name="br.com.site.C" android:label="#string/app_name" />
<activity android:name="br.com.site.D" android:label="#string/app_name" />
</application>
And this is my Activity "A.java" source:
public class A extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
startActivity(new Intent(this, AtualizaDadosFrame.class));
}
}
I don't want open my app twice.
Thanks in advance!
I'm going to assume that you started the app initially (the first time) from an IDE (like Eclipse or IntelliJ). If so, this is a known bug in Android (see http://code.google.com/p/android/issues/detail?id=26658 ). Many people have struggled for days chasing this problem :-(
Please don't change the launchMode. This is not the correct way to solve this problem. The default (standard) launchMode is the one that works in most cases.
EDIT (Added link to workaround):
A simple workaround for this problem can be found at http://code.google.com/p/android/issues/detail?id=2373#c21
You should set the desired launch mode in your AndroidManifest.xml.
You can restrict this.....
Please go through below link.
Home key press behaviour
In my application there is a behavior that I don't understand. I have the MainActivity A as SingleTask.
It calls an Activity B that is SingleTask too.
When I press the Home button in the second activity to open another application, and after that I try to go to my application mantaining Home button pressed i always go to Main Activity, and I want second activity to be opened mantaining the state that had when i press Home button.
I've tried setting then second activity to singleTop and it doesn't work.
Any help?
The behaviour of activity back stack becomes quit weird when define main activity with singleTask at the same time:
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What even worse is there is no clear explanation in the official dev guide regarding to this special use case. Some sections related to this topic are even self-contradictory.
Try using launchMode="standard" on your MainActivity A, and launchMode="singleTask" on your Activity B, which will give the expect behaviour you described.