【发布时间】:2017-06-06 17:02:57
【问题描述】:
(对不起我的英语)
我的第一个项目需要帮助,我必须在周五完成学习课程...
我正在尝试创建一个应用程序,该应用程序将显示一个通知,其中包含添加提醒的表中的描述。我对显示下一个描述的机制有疑问。显示通知后,我对应用程序进行了描述。不幸的是,当应用程序关闭时,这不起作用。
public void onReceive(Context context, Intent intent) {
ScheduleNotification.completeWakefulIntent(intent);
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
descToShow = d1;
DataBaseHandler dbh = new DataBaseHandler(context);
dbh.open();
dbh.DeleteRow(descToShow);
dbh.close();
Toast.makeText(context, descToShow, Toast.LENGTH_LONG).show();
//notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.icon);
builder.setContentTitle(descToShow);
builder.setContentText(descToShow); //--description event--
builder.setAutoCancel(false).build();
//from android dev:
Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT );
builder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, builder.build());
PendingIntent notifyPIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
builder.setContentIntent(notifyPIntent);
}
有什么想法吗?
我的github上的所有代码:https://github.com/azernax/dForget
【问题讨论】:
-
不要为每个值使用单独的
SharedPreferences- 一个可以容纳所有值。相关值应存储在一个文件中
标签: android background notifications task