resuming an activity from a notification

前端 未结 7 2177
刺人心
刺人心 2020-11-30 12:24

I have a notification in the status bar for my app:

    Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());

            


        
7条回答
  •  一向
    一向 (楼主)
    2020-11-30 12:52

    I have just found a solution this issue: I created getPreviousIntent method and gave it to PendingIntent that`s all:

    private Intent getPreviousIntent(Intent newIntent) {
        final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final List recentTaskInfos = am.getRecentTasks(1024,0);
        String myPkgNm = getPackageName();
    
        if (!recentTaskInfos.isEmpty()) {
            ActivityManager.RecentTaskInfo recentTaskInfo;
            for (int i = 0; i < recentTaskInfos.size(); i++) {
                recentTaskInfo = recentTaskInfos.get(i);
                if (recentTaskInfo.baseIntent.getComponent().getPackageName().equals(myPkgNm)) {
                    newIntent = recentTaskInfo.baseIntent;
                    newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                }
            }
        }
        return newIntent;
    }
    

提交回复
热议问题