Firstly, the use case: 2 phones opened my application on the same screen. I want one user to be able to share screen contents (data) with another, without necessarily opening a new instance of activity when shining using NFC. (Ice Cream Sandwich runs on both Android devices)
So, I have a singleTop activity declared like this in the manifest.
<activity android:name=".activity.MyActivity" android:configChanges="orientation|keyboardHidden" android:launchMode="singleTop"> <intent-filter android:label="@string/activityLabel"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="abc/xyz" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="application/xyz"/> </intent-filter> </activity>
When the VIEW action is executed and the activity is already on top, the onNewIntent() method is called on the instance if it is the action.
When the NDEF_DISCOVERED action NDEF_DISCOVERED started and the action is already enabled, the onCreate() method is called on the new instance.
source share