从通知打开时,标记未显示UI

时间:2016-02-21 19:24:56

标签: java android android-intent notifications fragment

我正在开发我的第一个项目,并且有一个片段显示UI中的计时器。每隔1小时,UI会通知用户并允许用户在选择通知栏时导航回该计时器标记。

  

问题是当我选中通知栏时,会调用该活动   并打开TimerFlagment,但是只有白色空白   屏幕,所有用户界面都消失了。

以下是发出通知的方法。

public void issueNotification(String action, String message){
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.setAction(action);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.icon_app)
                    .setContentTitle("My Application")
                    .setContentText(message)
                    .setContentIntent(PendingIntent.getActivity(
                            this,
                            0,
                            resultIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT
                    ));
    int mNotificationId = 001; // Sets an ID for the notification
    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(mNotificationId, mBuilder.build()); 
    Log.w("TimerFragment","Issue Notification");
}

这是MainActivity中的代码,我检查是否从通知中调用MainActivity。

try{
        String action = getIntent().getAction();
        if(action != null){
            if(action.toUpperCase().equalsIgnoreCase("NAV_TO_TIMER")){
               // Log.w("MainActivity","Launch timer");
               if (fragmentList.get("timer") != null) {
                  Log.w("MainActivity", "TimerFragment is in memory");
                  getSupportFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.frame_container, fragmentList.get("timer")).commit();
               }
            }
        } 
    }catch(Exception e){
        Log.e("MainActivity", "Problem consuming action from intent", e);
    }

我真的很擅长实现通知,我得到的代码来自link

提前感谢您,任何答案都表示赞赏。

0 个答案:

没有答案