In some situations (I do not know exactly what causes this to happen),
if I start my app, open another (here AaaActivity) activity and then click the home button to get to the phone home view, and then click the app icon from there, it starts in the application home view, instead of starting in the last open activity.
Why is this and what do I need to do to make it return to the last used activity (AaaActivity)?
Here is an excerpt from the manifest:
<activity
android:name="x.y.app.android.SsssActivity"
android:theme="#style/NoTitleBarNoBackground">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="x.y.app.android.AaaActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/activity_videoview"
android:launchMode="singleTop"
android:screenOrientation="sensorLandscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="x.y.app.android.AaaName" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Multiple tasks can be held in Android OS in the background at once. However, if the OS is running many background tasks at the same time, the system might begin destroying background activities in order to recover memory, causing the activity states to be lost. This is OS design and you can't prevent it. What you can do is saving your state so that you can retrieve it next time. Tasks in Android
Related
Good day, I'm doing a project and, I'm new with android development also, I just want to ask how to display my[the] splash screen first on my app (when starting up my application). Whenever I run it on emulator or on my device it directly go to my main activity.
Splash Screen Image
Main NavDrawer
I even reorder my manifest file list - and place the splash screen first
here my code
<!-- For Splash Screen -->
<activity
android:name=".activities.SplashScreen"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- For Main Activity -->
<activity android:name=".activities.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Whenever I exit my app and start again, my splash screen is gone! It directly go to Main Activity.
Thanks in advance! :)
You are having 2 LAUCHERS...
Make sure that only the Splash Screen Activity is the LAUNCHER.
Let the Main Activity be a DEFAULT one (and also the HOME one).
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.
When my app is started with a custom url scheme it does not appear in the "recent apps" list (appears on holding the home button).
Example:
I start my app from a link in an SMS. My app launches. This is ok.
Then I press the Home button and go to the home screen. Still ok.
Then I hold the Home button and the list of recent apps appears. My app is not on the list. This in not ok - I would expect my app to be on this list.
If I select the Messaging app from the list my app comes up. This is not ok. I would expect to see the Messaging app instead.
AndroidManifest.xml:
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<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.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="myhost.com" android:scheme="http" android:pathPattern="/Y.*"/>
</intent-filter>
</activity>
I believe what's happening is that your activity is being launched with an affinity to the task (application) that launched it, rather than launching a new task (your application).
Try setting the launchMode of your activity to singleInstance (the default is standard).
i.e.:
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
(Note: check the above linked launchMode documentation as you may prefer singleTask over singleInstance depending on what you are trying to achieve with your application.)
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've an application with a lot of activities. When returning from desktop or lockscreen, the expected behaviour is, that the last used activity is shown again.
This works flawlessly if the application is started again from the normal desktop icon. But if I add it to the lockscreen "widgetlocker" and start it from there, there is always the main activity shown. And unfortunately, if I close the main activity later by returning via back button, I return to all other instances of this main activity.
It might be related to the fact that I'm returned to the lockscreen when closing the application directly after having opened it from the lockscreen.
But I'm quite puzzled why the behaviour is different if I open from lockscreen or open normally.
Any suggestions? How can I force the application to be ALWAYS return to the last used screen?
...
# main activity:
<activity android:name="StudyOptions"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation|locale">
<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.VIEW" />
<category android:name="com.ankidroid.category.DECK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.anki" />
</intent-filter>
</activity>
<activity android:name="DeckPicker"
android:label="DeckPicker"
android:configChanges="keyboardHidden|orientation|locale"/>
...
how about maintaining the activity changes like a state machine. Giving a state number for each activity and persist the current in the database. And recover the last state from the database on startup and display the corresponding activity.