2013-05-25 105 views
0

我設置前景調度,如:的Android保存在屏幕上旋轉前景派遣

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); 
} 

但是,當屏幕旋轉前景調度結束調用公共無效onNewIntent(意向意圖) 。

我做錯了什麼?

+1

當屏幕方向更改活動被破壞並重新創建時。 – Raghunandan

+0

好吧,但....我只能調用onResume()行動enableForegroundDispatch(),所以...我必須做什麼來保存狀態或重新啓用ForegroundDispatch在屏幕上的旋轉? –

+0

http://developer.android.com/guide/topics/resources/runtime-changes.html。檢查onSavedInstanceState()和onRetainInstanceState() – Raghunandan

回答

0

也許您的mPendingIntent包含對您的活動的不再存在的先前實例的引用。重新創建PendingIntent,事情可能會按照您的意圖開始工作。