0

フォアグラウンドディスパッチを自由に無効/有効にできますか。onresume/onpause は、アクティビティがフォーカスに戻ったときとフォーカスが外れたときにそれぞれ有効化および無効化するのに役立ちます。

フォアグラウンドディスパッチを有効にしてから無効にする可能性はありますか。

IntentFilter を使用しようとしても writeTagFilters2[]= new IntentFilter[] { }; adapter.enableForegroundDispatch(this, pendingIntent, writeTagFilters2, null);

反応する意図を与えない

しかし、それは言うエラーを出します

フォアグラウンド ディスパッチは、アクティビティが再開されたときにのみ有効にできます。

4

1 に答える 1

3

I believe you should be using disableForegroundDispatch(Activity) in order to remove the registration for the callback.

From the documentation for enableForegroundDispatch:

This method must be called from the main thread, and only when the activity is in the foreground (resumed). Also, activities must call disableForegroundDispatch(Activity) before the completion of their onPause() callback to disable foreground dispatch after it has been enabled.

So provided your enable and disable calls reside between the onResume() and onPause() callbacks in the activity lifecycle, you can call them whenever.

Regarding your error, that code must be outside of the resume/pause events. Is it in your onCreate() method by any chance?

于 2013-05-25T01:59:54.710 に答える