私は、アクティビティから開始してバインドするサービスを持っています。アクティビティのOnDestroyメソッドでは、サービスにバインドを解除します。サービス通知を表示し、startForeground()を使用してフォアグラウンドに配置します。サービスのonUnbind()メソッドでは、stopself()とstopForeground(true)を呼び出します。しかし、サービスが機能しなくなっているようです。アプリは終了し、通知は消えていますが、アンドロイドスタジオのアンドロイドメモリモニターは継続しています。なぜこうなった? stopForeground()を呼び出すサービスで関数を作成し、アクティビティのOnDestroyの前に呼び出すと、アプリケーションは正常に終了します。メモリーモニターが停止します。 OnCreate関数でAndroidサービスMarshmallowで止まらない
MainActivity():OnDestroyで
service = new Intent(MainActivity.this, Service.class);
service.setAction("START");
startService(service);
if(myservice == null)
{
Intent k = new Intent(this,Service.class);
bindService(k, myConnection, Context.BIND_AUTO_CREATE);
}
MainActivity()
unbindService(myConnection);
サービスOnCreate関数()
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setAction("new");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Myservice")
.setTicker("service")
.setContentText("Monitoring")
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
.setContentIntent(pendingIntent)
.setOngoing(true).build();
startForeground(101, notification);
「しかし、アンドロイドスタジオのアンドロイドメモリモニターは続ける」 - 私はあなたに何を「続ける」かを知らない。あなたがサービスを停止しただけで、あなたのプロセスは遠ざかりません。 [プロセスは引き続き実行されます](http://developer.android.com/guide/components/processes-and-threads.html#Processes)。同様に、自分がフォークしたスレッドなど、設定した他の進行中の作業は引き続き実行されます。あなたのサービスがこの種のことをしたなら、あなたは 'onDestroy()'やその他の可能性のある点でその情報を整理する必要があります。 – CommonsWare
@ CommonsWare-なぜ、この問題は通知とStartForground()を使用した場合にのみ発生しますか? – amanda45
"この問題"が何であるかわからないので、私はそれに答えることはできません。あなたの質問を編集し、「アンドロイドスタジオのアンドロイドスタジオでのアンドロイドメモリモニタの継続」の意味を詳しく説明してください。 – CommonsWare