2

I am developing an android app with Min-TargetSDK=3 and TargetSDK=15. Previously also I have asked question related to my app not getting minimized to Recent Apps on home button press. Whenever I launch my app it starts from login page instead of showing last viewed screen. But I found no solution until now.

Somehow I managed to bring last viewed activity when user switches to some other task from app by pressing home button. Still app is not being minimized to Recent apps.

Now am facing some different problem:

Scenario 1 - OKAY:

  1. Install my app from apk file copied to sd card
  2. clicked Done after installation.
  3. Then open it by clicking launcher icon.

In this scenario, if user clicks home button when using the app and reopens the app by using launcher icon, last viewed screen is showing up. But still app not listed under Recent Apps list.

Scenario 2 - PROBLEMATIC:

  1. Install my app from apk file copied to sd card
  2. Open it by clicking "open" button after installation.

In this scenario, if user clicks home button when using the app and reopens the app by using launcher icon, last viewed screen is NOT showing up. Instead it starts from login page. Also app not listed under Recent Apps list. Here is my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.net.elderlyhealth"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<uses-permission android:name="android.permission.CALL_PHONE"/>

<uses-sdk android:minSdkVersion="3"
    android:targetSdkVersion="15"/> 

<application 
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".ElderlyActivity" android:alwaysRetainTaskState="true"
        android:label="@string/title_activity_elderly" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity  android:name=".ElderlyHealthAct" />


    <activity android:name=".account.LoginPage"  />
    <activity android:name=".account.SignupPage" />
    <activity  android:name=".account.RoleNavigator" />
    <activity  android:name=".account.CreateRoleActivity"  />
    <activity  android:name=".account.RoleAdmin"/>
    <receiver   android:name=".server.AlarmReceiver"></receiver>

</application>

</manifest>
A--C
  • 36,351
  • 10
  • 106
  • 92
Nandhu
  • 121
  • 1
  • 11
  • I think you should post your manifest XML. – dmon Feb 23 '13 at 01:35
  • ya i have posted my manifested file in the question itself.. – Nandhu Feb 23 '13 at 01:59
  • 1
    First I don't know why you expect it to show a last-viewed screen after a fresh install. Second there must be some condition under which your login screen is being triggered (like some security context is not there?). Can you look into what may be triggering the login screen and add this to the question? – hack_on Feb 23 '13 at 02:17
  • i understand what u r saying.but i did not expect it for first time.after installed it for first time and the user started using the app, the subsequent visits to app after home button press only am facing such problem. Am using sharedPrefrences to store user sessions.Can u explain what u mean by security context issue here? – Nandhu Feb 23 '13 at 02:24
  • @Nandhu Don't worry about SecurityContext. I was just trying to understand what was causing the login page to be displayed. At this point I suspect a coding bug in the activity lifecycle code (onCreate, onResume, onStop, onPause etc) but it is hard to say without more info. – hack_on Feb 23 '13 at 02:49
  • thanks for ur response hack_on!! i found my problem fixed but unfortunately i cant answer my own question as of now. i will post it after 7 hours.Its actually a bug in eclipse. i referred here to solve this: http://code.google.com/p/android/issues/detail?id=2373#c21 thanks for taking time to help me.. – Nandhu Feb 23 '13 at 02:56

1 Answers1

2

I think this will work for your 2nd scenario . You can check flag FLAG_ACTIVITY_BROUGHT_TO_FRONT in onCreate() of your first activity and then finishing if it is set.

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
    // Here activity is brought to front, not created,
    // so finishing this will get you to the last viewed activity
finish();
return;
    }

// Regular code.
}
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437