简体   繁体   中英

Android : resuming an app after an opening notification push

Here's my problem:

I have an application which includes 3 activities.

-SplashscreenActivity (Launcher - Main)

-LoginActivity

-HomeActivity

--Application killed:-- Normal process:

  1. when I run the application by the dashboard icon, I go through the splash, (i logged in), and coming up on the home. If I put the application in background and I raise it by the dashboard icon, I go back on the home. Everything is normal.

--Application killed:-- However, for the following process:

  1. I get a push notification. I run the application by this push, I go through the splash, and coming up on the home. But if I put the application in the background, and I raise it by the dashboard icon, I go through by the splash again systematically. Here is the problem!

Here's my manifest.xml ( EDITED )

<activity           
    android:name="my.package.SplashscreenActivity"
    android:label="@string/app_name"
    android:noHistory="false"
    android:screenOrientation="portrait">
    <intent-filter>
         <action android:name="android.intent.action.MAIN"/>
         <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

<activity
    android:name="my.package.LoginActivity"
    android:label="@string/app_name"
    android:noHistory="false"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustResize">
</activity>

<activity
    android:name="my.package.HomeActivity"
    android:label="@string/app_name"
    android:noHistory="false"
    android:launchMode="singleTask"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustResize">
</activity>

Here's my push notifications BroadcastReceiver (sendNotificationMethod)

private void sendNotification(String message, String title, int count, String type, long threadId)
{
    Activity m_activity;
    if (App.getInstance().m_currentActivity != null && App.getInstance().isOnPause())
        m_activity = App.getInstance().m_currentActivity;
    else
        m_activity = null;

    PendingIntent pendingIntent = null;
    Intent intent = null;

    if (m_activity != null)
    {
        intent = new Intent(this, m_activity.getClass());
        intent.putExtra("type", type);
        intent.setData((Uri.parse("foobar://" + SystemClock.elapsedRealtime())));
        pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    }
    else
    {
        PackageManager pm = getPackageManager();
        intent = pm.getLaunchIntentForPackage("my.package");
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("type", type);
        pendingIntent = PendingIntent.getActivity(App.getInstance(), 0, intent, 0);
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.logo_push_lolilol)
            .setColor(App.getInstance().getResources().getColor(R.color.colorPrimary))
            .setContentTitle(title)
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(message));

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


    notificationManager.notify((int)threadId, notificationBuilder.build());
}

Do you have "the solution"?

Thank you in advance.

Try this

intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM