【问题标题】:Why doesn't open the service my activity?为什么我的活动不打开服务?
【发布时间】:2014-05-23 17:24:23
【问题描述】:

我的问题是,如果我点击通知,它会关闭但不会打开活动 垂直计划。有什么问题?

这是我的代码:

@Override
        public int onStartCommand(Intent intent, int flags, int startId) {
            // TODO Auto-generated method stub
            int auswertungsergebnis = 0;
            boolean weekday = checkDay();
            if (weekday == true) {
                auswertungsergebnis = auswerten();
            }
            String ausgabe = ausfaller.toString().replace("[", "").replace("]", "");
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(ACTION);
            registerReceiver(notifyServiceReceiver, intentFilter);

            // Send Notification
            notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            myNotification = new Notification(R.drawable.ic_stat_gymi,
                    "Notification!", System.currentTimeMillis());
            Context context = getApplicationContext();
            String notificationTitle = "Neue Vertretungsstunden!";
            String notificationText = ausgabe + " fällt heute aus";
            Intent myIntent = new Intent(context, Vertretungsplan.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(
                    getBaseContext(), 0, myIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
            myNotification.defaults |= Notification.DEFAULT_SOUND;
            myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
            myNotification.setLatestEventInfo(context, notificationTitle,
                    notificationText, pendingIntent);

            if (auswertungsergebnis == 1) {
                notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
            }
            return super.onStartCommand(intent, flags, startId);
        }

提前谢谢你:)

【问题讨论】:

    标签: android android-intent service notifications


    【解决方案1】:

    您将Intent.FLAG_ACTIVITY_NEW_TASK 传递给PendingIntent.getActivity - 该标志需要添加到Intent 本身:

    Intent myIntent = new Intent(context, Vertretungsplan.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(
        getBaseContext(), 0, myIntent, 0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-20
      • 2020-03-14
      • 1970-01-01
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多