我正在为Android设置地理栅栏应用程序。在谷歌的example的帮助下,并从IntentService
到BroadcastReceiver
重构here我现在有一个应用程序,如果应用程序在后台,按预期工作。我没有管理的是我如何更新我的应用程序,例如一个模型,如果应用程序被杀害?我的GeofenceReceiver
在应用程序被杀时触发/调用,但我的BroadcastReceiver
消息未在我的MainActivity
中收到。如何从IntentReceiver更新关闭/杀死的应用程序?
在我GeofenceReceiver
我做这样的事,如果我得到一个地理围栏的过渡:正如我已经说过广播接收
Intent broadcastIntent = new Intent(ACTION);
broadcastIntent.putExtra("resultCode", Activity.RESULT_OK);
broadcastIntent.putExtra(Constants.BUNDLE_KEY, bundle);
LocalBroadcastManager.getInstance(context).sendBroadcast(broadcastIntent);
:
1:
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putStringArrayListExtra(Constants.TRIGGERING_GEOFENCE_IDS_KEY, triggeringIDs);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setColor(Color.RED)
.setContentTitle(notificationDetails)
.setContentText(context.getString(R.string.geofence_transition_notification_text))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(resultPendingIntent);
builder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, builder.build());
2在我的MainActivity
中,如果应用程序在后台。如果我杀了App,我的MainActivity
没有收到广播。我检查了与终端和logcat。
任何想法?
那么你的意思是你在你的BroadcastReceiver中收到了一个广播,但是你没有在你的主要活动中得到它? – cafebabe1991
@ cafebabe1991基本上是的。即使应用程序被杀死,我的GeofenceReceiver仍然会被要求进行地理栅栏转换,但之后我无法向我的MainActivity广播某些内容。 – wman