마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

nfc activity 중복실행문제

+1 추천

회사에서 개발중인 프로그램에 nfc 기능이 붙어서 이번에 기능을 추가 했는데요

다른 기능은 다 문제가 없는데

nfc 태그로 액티비티를 최초 실행했을때

 onNewIntent(Intent intent) 가 호출되야하는데

onCreate(Bundle bd) 가 호출되면서 액티비티가 새로 뜨네요

최초 실행 됬던 액티비티는 살아있구요

그 뒤로 실행된 두번째 액티비티에서는 제대로 동작합니다.

상용되있는 앱이라 이건 치명적인 오류인데

제가 봤을때는 enableForegroundDispatch 할때 intent를 잘 못 넘겨주는거 같은데...

이걸 해결하는 방법이 없을까요?

 

아래는 enableForegroundDispatch 부분입니다.

private void enableForegroundDispatch() {
Log.d(TAG, "enableForegroundDispatch");
NfcAdapter nfcAp = NfcAdapter.getDefaultAdapter(this);
Intent intent = new Intent(this, getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
 
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
String[][] filter = new String[][] { new String[] { "android.nfc.tech.NfcF" } };
 
try{
nfcAp.enableForegroundDispatch(this, pi, null, filter);
}catch(Exception e){
Log.e(TAG, "enableForegoundDispatch error");
e.printStackTrace();
}
PuHit (270 포인트) 님이 2013년 7월 1일 질문

1개의 답변

+1 추천
 
채택된 답변

해당 액티비티에 다음을 입력 합니다.

<activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleInstance" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
aucd29 (218,390 포인트) 님이 2013년 7월 1일 답변
PuHit님이 2013년 7월 1일 채택됨
...