【问题标题】:Android save foreground dispatch on screen rotationAndroid在屏幕旋转时保存前台调度
【发布时间】: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


【解决方案1】:

也许您的 mPendingIntent 包含对您的 Activity 的不再存在的先前实例化的引用。重新创建 PendingIntent,事情可能会开始按您的预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多