AlarmManagerを介して起動される簡単なステータス通知を作成しました。すべてが正常に機能します(通知の内容、タイトル、タップされたときに開始されるアクティビティなど)。残念ながら、通知が呼び出されると(つまり、AlarmManagerがオフになると)、空のアクティビティが起動されて表示されます。アクティビティには、ステータスバーにアプリの名前とそのアイコンが表示されます。実際のアクティビティ自体は空白です。繰り返しになりますが、これは通知がオフになり、ステータスバーに初めて表示されたときに発生します。通知をもう一度タップすると、正しい保留中のアクティビティに移動します。これが私のコードです:
通知を呼び出すようにAlarmManagerを設定するコードは次のとおりです。
//Use AlarmManager to trigger the notification/alarm.
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
//PendingIntent to launch activity when the alarm triggers.
Intent intent = new Intent("com.YouForgotWhat.FlightGear.DisplayNotification");
PendingIntent displayIntent = PendingIntent.getActivity(getBaseContext(), 0, intent, 0);
//Set an alarm to go off at 30 minutes before fuel runs out.
alarmManager.set(AlarmManager.RTC_WAKEUP, endTimeInMillis - (30*60*1000), displayIntent);
そして、これが通知自体の実際のコードです(別のアクティビティにあります):
public class DisplayNotification extends SherlockActivity {private Context context = this;
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle("Your fuel may be running low.")
.setContentText("There are 30 mins left on your timer. Check your fuel gauges.")
.setSmallIcon(R.drawable.ic_launcher);
Intent intent = new Intent(this, FuelTimer.class);
PendingIntent in = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
mBuilder.setContentIntent(in);
mNotificationManager.notify(0, mBuilder.build());
}
}
この問題を解決するにはどうすればよいですか?ありがとう!