AndroidでIntentを発行した時に、同一のIntent(データURIも同一)によって起動したタスクが存在する場合、 タスクがフロントにやってくるのみでActivityが起動しないという挙動をするようです。
例としてadb経由でIntentを発行してみます。
adb shell am start \
-a android.intent.action.VIEW \
-d 'testapp://sample?message=hello'
Starting: Intent { act=android.intent.action.VIEW dat=testapp://sample?message=hello }
Warning: Activity not started, its current task has been brought to the front
Warning: Activity not started, its current task has been brought to the front
とある通り、
Intentは発行されアプリは最前面に来るものの、Activityは立ち上がらずIntentも渡されません。
- データとして渡すURIが異なる場合は、問題なくActivityが立ち上がります。
- タスクが該当のIntent以外のIntent(LAUNCHERなど)によって起動した場合もまた、発生しません。
同一のIntentであっても受け取りたいので、Intentを受信するActivityをsingleTaskで起動するようにしました。 起動した後に別のsingleTaskのActivityを起動することで、同一のIntentでも受け取れるようになりました。 ちょっと無理やりな方法なので、これが正しい方法かどうかはわかりません。
<activity android:name=".ReceiveActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="testapp" android:host="sample" />
</intent-filter>
</activity>