2017-04-20 47 views
1

以下是我的问题:Android:在开放通知推送后恢复应用程序

我有一个包含3个活动的应用程序。

-SplashscreenActivity(发射器 - 主)

-LoginActivity

-HomeActivity

--application杀: - 正常流程

  1. 当我运行应用程序仪表板图标,我经历了飞溅,(我登录),并在家里。 如果我把应用程序放在后台,并且通过仪表板图标提出,我回到家中。一切正常。

--application杀死: - 然而,为了下面的处理:

  • 我得到的推送通知。我通过这个推动来运行应用程序,我经历了一次飞溅,然后回到家中。 但是,如果我把应用程序放在背景中,并且我通过仪表板图标来提高它,那么我会再次系统地通过飞溅。这是问题!
  • 这里是我的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> 
    

    这里是我的推送通知广播接收器(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()); 
    } 
    

    你有 “解决”?

    预先感谢您。

    +0

    删除此'机器人:launchMode = “singleTop”'。 –

    +0

    @DheerubhaiBansal它不会改变任何东西。 – museehomme

    回答

    0

    试试这个

    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); 
    
    +0

    问题仍然存在... 但我认为它不是pendingIntent谁第一次启动应用程序的问题,但应用程序恢复。 pendingIntent通常启动应用程序,但是当我将应用程序放在backeground中时,我再次打开它,出现了一些问题。 – museehomme