2017-06-08 61 views
0

所以这里是我在这里想要实现的......我们在设备上安装了两个android APK ...每个APK都可以强制自己处于前台(这不是应用程序一般大众都会用,所以没关系......)FLAG_ACTIVITY_REORDER_TO_FRONT无法在某些设备上工作

  • 所以我们用activity a来启动任务a。
  • 然后我们用活动b启动任务b。
  • 然后活动&任务要去前台
  • 在某一点后(这可以发生在任何时间),活动和任务想去前景

所以我们有这个代码工作使用以下代码:

Intent i = new Intent(Variables.context, HomeActivity.class); 
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
startActivity(i); 

太棒了!

但是,在运行4.2.2(也可能是其他人)的电话上,我们注意到这种行为与预期不符。以下两件事情可能发生。

让我们假设活动a &任务a在前台,但想要使活动b和任务b到达前台它不起作用。

但是如果没有任务是在前台和家庭发射集中,然后活动B和任务B被预期弹出到前台。

下面是从应用的一个我清单的一个示例:

<activity 
      android:name="some.app.id.goes.here" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" 
      android:windowSoftInputMode="adjustPan"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

我曾尝试加入这一行的代码:

android:launchMode="singleTop" 

,它仍然无法正常工作。

有什么我失踪?

的几个注意事项:

  • 活动A可以是任何应用程序,而不仅仅是我们开发的应用程序,从发生停止这排除了活性的。我们使用谷歌浏览器/ Google地图/ Google Play商店获得了相同的结果。
  • 我们不覆盖onNewIntent
+0

你为什么不创建活动堆栈的数组列表将非常容易管理。 –

+1

供您参考,你可以做一些事情[这样的](https://stackoverflow.com/a/38326848/5860777)。 –

回答

0

那么,什么是痛苦这是...

这里是解决办法,我不得不做...

private void generateNotificationToPopActivityToTop(final int id, Context context, String message) { 
     Intent notificationIntent = new Intent(context, HomeActivity.class); 
     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); 

     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setContentTitle(context.getString(R.string.app_name)) 
       .setFullScreenIntent(intent, true) 
       .setPriority(NotificationCompat.PRIORITY_MAX) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS); 
     final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     mNotificationManager.notify(id, mBuilder.build()); 

     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       mNotificationManager.cancel(id); 
      } 
     }, 1000); 

    } 
相关问题