从通知导航到父活动

Sav*_*ing 5 notifications android push-notification parse-platform

My question is that I have two activities, Activity A and Activity B. Activity A is the main activity, Activity B is only accessible by touching a notification.

I need to be able to touch a notification, which will open Activity B. After the user is finished with Activity B, they can press the back button or finish Activity B. When Activity B closes, Activity A should be shown. Currently, I close Activity A (which closes the entire app) and receive a push notification. I select the push notification which opens Activity B. When I close Activity B, Activity A is not shown and the entire app closes. I want Activity A to be there after finishing Activity B.

I am using Parse SDK notifications. In my custom ParsePushBroadcastReceiver I have the following code

public class MyReceiver extends ParsePushBroadcastReceiver 
{
  @Override
  public void onPushOpen(Context context, Intent intent) 
  {        

    Intent i = new Intent(context, NotificationActivity.class);
    i.putExtras(intent.getExtras());
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    context.startActivity(i);
  }
}
Run Code Online (Sandbox Code Playgroud)

I have it listed in the Android Manifest. My notification activity in manifest is

<activity
        android:name=".NotificationActivity"
        android:label="@string/app_name" 
        android:windowSoftInputMode="adjustPan"
        android:screenOrientation="portrait"
        android:parentActivityName=".MainActivity">

    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity"/>

</activity>
Run Code Online (Sandbox Code Playgroud)

在我的通知活动中,我在 onBackPressed 中有以下代码

public class NotificationActivity extends ActionBarActivity
{...
   @Override
   public void onBackPressed() 
   {
      if(NavUtils.getParentActivityName(this) != null)
      {
        Log.d(Constants.NAVIGATION_DEBUG, "Get Parent Activity NOT NULL"); 

        NavUtils.navigateUpFromSameTask(this); 
      }
      else
      {
        Log.d(Constants.NAVIGATION_DEBUG, "Get Parent Activity NULL"); 

        super.onBackPressed();
      } 
     }
...}
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,在日志中,它声明它不是 NULL,但是如果在按下通知之前关闭了应用程序,它不会导航回活动 A。而是关闭应用程序。我希望 Activity A 显示按下通知时应用程序是否关闭或应用程序是否打开。谢谢!

Pra*_*jal 0

对于临时解决方案,您必须在NotificationActivity的onBackPress()上启动MainActivity..