简体   繁体   English

Android:在打开通知推送后恢复应用

[英]Android : resuming an app after an opening notification push

Here's my problem: 这是我的问题:

I have an application which includes 3 activities. 我有一个包含3项活动的申请。

-SplashscreenActivity (Launcher - Main) -SplashscreenActivity(Launcher - Main)

-LoginActivity -LoginActivity

-HomeActivity -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 ) 这是我的manifest.xml(已编辑

<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) 这是我的推送通知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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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