2017-09-29 1 views
0

NFC 카드에서 읽는 애플리케이션을 개발 중입니다. 문제는 다음과 같습니다. 사용자가 응용 프로그램 시작 아이콘으로 응용 프로그램을 시작했습니다.NFC Android 애플리케이션이 두 번 시작되었습니다.

<activity 
android:name="com.d_logic.cardcontrol.SplashScreenActivity" 
android:screenOrientation="portrait"> 
<intent-filter> 
    <action android:name="android.intent.action.MAIN"/> 
    <category android:name="android.intent.category.LAUNCHER"/> 
    <action android:name="android.nfc.action.TECH_DISCOVERED"/> 
</intent-filter> 
    <meta-data> 
    <android:name="android.nfc.action.TECH_DISCOVERED"> 
    <android:resource="@xml/techlist"/> 
</activity> 

응용 프로그램이 시작되고있는 동안 사용자 보도 홈 버튼 후 : 매니페스트에서

//Initialize Foreground NFC Dispatch System 
mAdapter = NfcAdapter.getDefaultAdapter(this); 
context=this; 
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, 
getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); 
try { 
ndef.addDataType("*/*"); /* Handles all MIME based dispatches. 
          You should specify only the ones that you need. 
*/ 
} 
catch (IntentFilter.MalformedMimeTypeException e) { 
throw new RuntimeException("fail", e); 
} 
mFilters = new IntentFilter[] { ndef, }; 
mTechLists = new String[][] { new String[] { MifareClassic.class.getName() } 
}; 

내가 가진 : 응용 프로그램이 포 그라운드 디스패치 시스템을 구현, NFC 카드를 스캔 할 준비가되어 있습니다. 그런 다음 백그라운드에서 응용 프로그램을 실행하면 사용자가 응용 프로그램을 다시 시작하지만 이번에는 NFC 카드를 사용합니다.

현재 두 개의 동일한 응용 프로그램 인스턴스가 실행 중입니다.

두 번째 응용 프로그램을 시작할 수 없지만 NFC 카드를 사용하여 응용 프로그램을 시작할 수있는 방법은 무엇입니까? 감사합니다. 활동의 동일한 인스턴스가 바로 앞에 가져되도록 매니페스트에

//put here in variable global 
private long twiceCall; 
private static final int time_interval = 1500; 

// and put this to avoiding twice calling 
if (twiceCall + time_interval > System.currentTimeMillis()) { 
     // If get the second time.. 
} else { 
     // Get the first time.. 
} 
twiceCall = System.currentTimeMillis(); 

답변

0

피하기 두 번이 논리를 사용하여 . 선택하는 모드는 정확한 사용 사례에 따라 다릅니다.

NFC 사용 사례에 대해 "singleTop"또는 "singleTask"가 아마도 작동 할 것입니다.

0

만들기 사용

android:launchMode:"standard/singleTop/singleTask/singleInstance" 

의 새로운 의도를 통과 :

관련 문제