0

In MainActivity, I call SincActivity. This screen has a "start" button, a TextView and a ProgressBar to show the status.

The button start an AsyncTask. This AsyncTask updates the components on the screen, and also in the notification area.

The notification area can be clicked. I passed into their creation which Activity it should open. I have spent SincActivity.

When the user is on the screen SincActivity and click the button, all components are updated as expected.

When I click on the notification area, android opens a new screen SincActivity, with initial values​​.

It's as if somewhere, android execute: "new SincActivity"; What I need is to be shown always the same screen.. the same instance. Almost like a singleton.

Is this possible?

UPDATE

AndroidManifest.xml

<uses-sdk
   android:minSdkVersion="11"
   android:targetSdkVersion="17" />

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

<application
   android:allowBackup="true"
   android:icon="@drawable/ic_launcher"
   android:label="@string/app_name"
   android:theme="@style/AppTheme" >
    <activity
       android:name="br.com.rokko.gabinetemobile.MainActivity"
       android:label="@string/app_name"
       android:configChanges="orientation|keyboardHidden|screenSize"
       android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
       android:name="br.com.rokko.gabinetemobile.ModeloActivity"
       android:configChanges="orientation|keyboardHidden|screenSize"
       android:label="@string/title_activity_modelo"
       android:theme="@style/FullscreenTheme" >
    </activity>
    <activity
       android:name="br.com.rokko.gabinetemobile.SincActivity"
       android:label="@string/sincronizacao" ><!-- android:launchMode="singleInstance" don't work -->
    </activity>
</application>

Falci
  • 1,823
  • 4
  • 29
  • 54

2 Answers2

0

Try adding android:launchMode="singleInstance" to the <activity> tag for this Activity in your AndroidManifest.xml file.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

If you just want the notification to bring your task to the foreground, without creating any new instances of activities, you need to use a "launch Intent" in your notification. Something like this:

    Intent intent = new Intent(this, MainActivity.class);
    // Set the action and category so it appears that the app is being launched
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

use pendingIntent when you create your notification.

For more information, see Android application current activity bring to front issue

Community
  • 1
  • 1
David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Thanks, but I could not make it work. This is right? http://pastebin.com/nF5mcyPd – Falci Jun 17 '13 at 12:51
  • Sorry, I made a mistake in the code. I've edited my answer. You want to use `MainActivity` in the notification Intent, not `SincActivity`. The reason is that you want to simulate "relaunching" your application. – David Wasser Jun 17 '13 at 13:49