【发布时间】:2015-12-16 10:27:39
【问题描述】:
如果应用程序已登录并在前台点击通知,那么我只想将用户带到活动新闻。如果应用程序处于后台,则将其置于前台并转到 NEWS 活动。如果应用程序未启动或不在后台,则显示 LOGIN 活动,然后在成功完全登录后将用户带到 NEWS 活动。
使用我的测试代码,如果用户未登录,我可以将用户带到新闻活动,但不能带到登录活动!
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, NewsActivity.class), 0);
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(this.getApplicationContext().getString(R.string.app_name))
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mBuilder.setAutoCancel(true);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
从其他线程我知道我们不应该使用 ActivityManager.getRunningTasks 来检查应用程序是否在前台!在所有活动的 onResume 和 onPause 上设置标志以检查应用程序是否在前台是唯一可用的最佳方法吗?
【问题讨论】:
标签: android android-activity notifications google-cloud-messaging