【发布时间】:2013-05-25 18:38:55
【问题描述】:
我设置了一个前台调度,例如:
mAdapter = NfcAdapter.getDefaultAdapter(this);
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
mFilters = new IntentFilter[] { new IntentFilter(
NfcAdapter.ACTION_TECH_DISCOVERED) };
// Setup a tech list for all NfcF tags
mTechLists = new String[][] { new String[] { MifareClassic.class
.getName() } };
我有:
@Override
public void onResume() {
super.onResume();
mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters,
mTechLists);
}
但是当屏幕旋转时,前台调度停止调用 public void onNewIntent(Intent intent)。
我做错了什么?
【问题讨论】:
-
当屏幕方向改变时,Activity被销毁并重新创建。
-
好的,但是....我只能在 onResume() 操作上调用 enableForegroundDispatch(),所以...我必须做些什么来保存状态或在屏幕旋转时重新启用 ForegroundDispatch?
-
developer.android.com/guide/topics/resources/…。检查 onSavedInstanceState() 和 onRetainInstanceState()
-
好的,所以我必须在屏幕旋转之间保存 NfcAdapter mAdapter 的状态。对吗?
-
是的。查看评论中发布的链接以获取更多信息
标签: android rotation screen nfc screen-rotation