我在显示通知之前在我的项目中写了一个通知,它在共享的优先级中保存了值。当应用程序打开并在活动中显示信息和我的值时它工作,但它在应用程序关闭时不起作用并且当应用程序关闭并且通知显示并且我单击它时,它显示活动空我加载共享的首选值该活动的Oncreate必须显示...但它是空的...请帮助我,当我点击Back Button It Crashed ... 我的通知代码。它可以节省价值并显示通知......
@Override
public void onSuccesResponse(JSONArray responseArray) throws JSONException {
if (responseArray.length() > 0) {
sharedPref = new SharedPref(apiManager.customer, apiManager.requesting, context);
if (!G.onecNotify) {
sharedPref.saveRequestData();
sharedPref.loadRequestData();
showNotification();
G.notificationShown = true;
requestListener.onResponseRequest(apiManager);
}
}
}
我的主要通知代码
private void showNotification() {
G.onecNotify = true;
String[] infoToShow = new String[2];
String sourceAddress = " آدرس مبدا :" + apiManager.requesting.getSourceAddress();
String destinetionAddress = " آدرس مقصد :" + apiManager.requesting.getDestinationAddress();
String contentNotification = "";
infoToShow[0] = sourceAddress;
infoToShow[1] = destinetionAddress;
for (int i = 0; i < infoToShow.length; i++) {
contentNotification += infoToShow[i] + "\n\n";
}
Intent intent = new Intent(context, RequestManagementActivity.class);
Intent stackIntent = new Intent(context, MainAccountActivity.class);
//PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = TaskStackBuilder.create(G.context)
.addNextIntentWithParentStack(stackIntent)
.addNextIntent(intent)
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.whistle)
.setContentTitle("شما درخواست ارسال بسته دارید")
.setContentIntent(pendingIntent)
.setColor(Color.parseColor("#ef9a9a"))
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
.setLights(Color.parseColor("#e91e63"), 1, 1)
.setStyle(new NotificationCompat.BigTextStyle().bigText(contentNotification))
.setContentText(contentNotification);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, builder.build());
}
我的活动必须显示。它加载值并在我的活动控件中设置
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_request_management);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("");
if (G.notificationShown) {
apiManager = new ApiManager();
sharedPref = new SharedPref(apiManager.customer, apiManager.requesting, G.context);
sharedPref.loadCustomerData();
sharedPref.loadRequestData();
init();
setControls();
}
}
whwn app关闭它显示活动空..我需要你的帮助请帮助我...... :(