0

我正在安排这样的警报管理器:

Intent myIntent = new Intent(context, Locale.class);
            intent.putExtra("end",AlarmEnd.getTimeInMillis());

            PendingIntent pendingIntent = PendingIntent.getService(context, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);


            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, AlarmStart.getTimeInMillis(), 40 * 1000, pendingIntent);

所以这是有效的......问题是它何时启动 Locale

public int onStartCommand(Intent intent, int flags, int startId) {
        int t = START_STICKY;
        SharedPreferences alarms = getApplicationContext().getSharedPreferences("alarms", 0);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        Log.i("LocalService", "Received start id " + startId + ": " + intent);
        client = new AsyncHttpClient();
        endTime = intent.getLongExtra("end",0);
        Log.d("Alarms", "End time is".concat(endTime.toString()));

调试消息总是输出默认值“结束时间为 0”。我知道额外的意图不是零(检查它)。我究竟做错了什么?

4

1 回答 1

1

问题已解决

Intent **myIntent** = new Intent(context, Locale.class);
            **intent**.putExtra("end",AlarmEnd.getTimeInMillis());

问题是我错误地设置了意图附加内容而不是“myIntent”附加内容的意图命名。傻我。

于 2013-05-16T01:30:35.357 回答