How the use same instances when launching application twice

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How the use same instances when launching application twice

Postby The_One_Neo » Mon Apr 13, 2009 10:28 am

My app has 4 activities on the stack A->B->C->D (top)


If you press home and re-enter the application, another instance of A
is started, so the stack is A->B->C->D->A (top). I know this because
when I press BACK, A is popped off and I now see D (instead of going
to the Home screen).


What I want is that when the user re-enters the app, they re-enter on
the same activity they were in before (D). How do you do that?
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Top

Postby padde » Mon Apr 13, 2009 2:05 pm

http://developer.android.com/guide/topics/manifest/activity-element.html

read the "android:launchMode" section there.


Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby The_One_Neo » Tue Apr 14, 2009 7:23 am

i tested add the android:launchMode="singleTask" no changed

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pica.msn"
android:versionCode="1"
android:versionName="1.0.0">
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".SplashActivity"
android:launchMode="singleTask"
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=".LoginActivity"
android:launchMode="singleTask"
android:label="@string/app_name">
</activity>
<activity android:name=".MainActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light">
</activity>

</application>
</manifest>
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby padde » Tue Apr 14, 2009 7:52 am

I think you have to combine this with Intent flags.

This one might help you
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP


Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby The_One_Neo » Tue Apr 14, 2009 9:14 am

i add flag in the intent

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent. FLAG_ACTIVITY_NEW_TASK);

but no changed

when i click twice app icon , the old instance be kill, and create a new instance
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby georgij » Mon Jun 08, 2009 10:16 pm

Hi The_One_Neo,

have you found a solution? I have the same problem and understand what you are trying to achieve.

Android seems not to have docs describing this problem and FLAG_ACTIVITY_CLEAR_TOP will not solve it since you want to stay with D and not pop everything down to A. I have achieved the stay with D by exiting the second A call in onCreate() (with finish(); return;) experimentally in the debugger but this is not a solution.
G1, what else.
georgij
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed Jan 14, 2009 12:22 am
Location: Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests