У меня есть Android-приложение, которое должно открывать файлы Json из приложений обмена сообщениями, но всегда в одной задаче. Никогда не должно быть двух запущенных приложений. Итак, я установил launchMode="singleTask"
. Вот фрагмент манифеста:
<activity
android:name=".MainActivity"
...
android:launchMode="singleTask"
<intent-filter>
...
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="content"
android:host="*"
android:pathPattern=".*\\.json"
android:mimeType="*/*"
/>
</intent-filter>
/>
Это работает во всех протестированных мною приложениях, кроме Telegram. Telegram открывает новое действие внутри своей задачи. Это показано в выводе adb shell dumpsys activity activities
, для com.myApp
есть два отдельных действия, и одно находится в Задаче Telegram:
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom):
Stack #1:
mFullscreen=true
mBounds=null
Task id #10571
mFullscreen=true
mBounds=null
mMinWidth=-1
mMinHeight=-1
mLastNonFullscreenBounds=null
* TaskRecord{3bd908f #10571 A=org.telegram.messenger U=0 StackId=1 sz=2}
userId=0 multiLaunchId=0 effectiveUid=u0a118 mCallingUid=u0a67 mUserSetupComplete=true mCallingPackage=com.huawei.android.launcher
affinity=org.telegram.messenger
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.telegram.messenger/org.telegram.ui.LaunchActivity}
realActivity=org.telegram.messenger/org.telegram.ui.LaunchActivity
autoRemoveRecents=false isPersistable=true numFullscreen=2 taskType=0 mTaskToReturnTo=1
rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
Activities=[ActivityRecord{75c4f1c u0 org.telegram.messenger/org.telegram.ui.LaunchActivity t10571}, ActivityRecord{b96c564 u0 com.myApp.debug/com.myApp.MainActivity t10571}]
askedCompatMode=false inRecents=true isAvailable=true
lastThumbnail=null lastThumbnailFile=/data/system_ce/0/recent_images/10571_task_thumbnail.png
stackId=1
hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE isResizeable=true firstActiveTime=1556706462633 lastActiveTime=1556706462633 (inactive for 250s)
* Hist #1: ActivityRecord{b96c564 u0 com.myApp.debug/com.myApp.MainActivity t10571}
packageName=com.myApp.debug processName=com.myApp.debug
launchedFromUid=10118 launchedFromPackage=org.telegram.messenger userId=0 multiLaunchId=0
app=ProcessRecord{d758be5 11733:com.myApp.debug/u0a187}
Intent { act=android.intent.action.VIEW dat=content://org.telegram.messenger.provider/media/Telegram/Telegram Documents/4_5904235303509427798.json typ=application/octet-stream flg=0x13000001 hwFlg=0x400 cmp=com.myApp.debug/com.myApp.MainActivity }
frontOfTask=false task=TaskRecord{3bd908f #10571 A=org.telegram.messenger U=0 StackId=1 sz=2}
taskAffinity=com.myApp.debug
realActivity=com.myApp.debug/com.myApp.MainActivity
baseDir=/data/app/com.myApp.debug-2/base.apk
dataDir=/data/user/0/com.myApp.debug
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f0b002d icon=0x7f0a0000 theme=0x7f0c0006
config={1.0 222mcc50mnc [it_IT] ldltr sw360dp w360dp h580dp 480dpi nrml port finger -keyb/v/h -nav/h suim:4 s.6}
taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
resultTo=ActivityRecord{75c4f1c u0 org.telegram.messenger/org.telegram.ui.LaunchActivity t10571} resultWho=null resultCode=500
taskDescription: iconFilename=null label="null" color=fff5f5f5
readUriPermissions={UriPermission{36a52f7 0 @ content://org.telegram.messenger.provider/media/Telegram/Telegram%20Documents/4_5904235303509427798.json}}
launchFailed=false launchCount=1 lastLaunchTime=-4m10s762ms
haveState=false icicle=null
state=RESUMED stopped=false delayedResume=false finishing=false
keysPaused=false inHistory=true visible=true sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_NOT_SHOWN
fullscreen=true noDisplay=false immersive=false launchMode=2
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=true lastVisibleTime=-4m10s504ms
resizeMode=RESIZE_MODE_RESIZEABLE
* Hist #0: ActivityRecord{75c4f1c u0 org.telegram.messenger/org.telegram.ui.LaunchActivity t10571}
packageName=org.telegram.messenger processName=org.telegram.messenger
launchedFromUid=10067 launchedFromPackage=com.huawei.android.launcher userId=0 multiLaunchId=0
app=ProcessRecord{8b7f51e 7395:org.telegram.messenger/u0a118}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.telegram.messenger/org.telegram.ui.LaunchActivity bnds=[276,370][540,656] (has extras) }
frontOfTask=true task=TaskRecord{3bd908f #10571 A=org.telegram.messenger U=0 StackId=1 sz=2}
taskAffinity=org.telegram.messenger
realActivity=org.telegram.messenger/org.telegram.ui.LaunchActivity
baseDir=/data/app/org.telegram.messenger-2/base.apk
dataDir=/data/user/0/org.telegram.messenger
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f0c00e0 icon=0x7f0700c0 theme=0x7f0d0015
config={1.0 222mcc50mnc [it_IT] ldltr sw360dp w360dp h580dp 480dpi nrml port finger -keyb/v/h -nav/h suim:4 s.6}
taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
taskDescription: iconFilename=null label="null" color=ff527da3
launchFailed=false launchCount=0 lastLaunchTime=-4m21s505ms
haveState=true icicle=Bundle[mParcelledData.dataSize=1212]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_SHOWN
fullscreen=true noDisplay=false immersive=false launchMode=2
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=false lastVisibleTime=-4m20s756ms
connections=[]
resizeMode=RESIZE_MODE_RESIZEABLE
Task id #10570
mFullscreen=true
mBounds=null
mMinWidth=-1
mMinHeight=-1
mLastNonFullscreenBounds=null
* TaskRecord{575db75 #10570 A=com.myApp.debug U=0 StackId=1 sz=1}
userId=0 multiLaunchId=0 effectiveUid=u0a187 mCallingUid=2000 mUserSetupComplete=true mCallingPackage=null
affinity=com.myApp.debug
intent={flg=0x10000000 cmp=com.myApp.debug/com.myApp.MainActivity}
realActivity=com.myApp.debug/com.myApp.MainActivity
autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=0 mTaskToReturnTo=0
rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
Activities=[ActivityRecord{d8a470a u0 com.myApp.debug/com.myApp.MainActivity t10570}]
askedCompatMode=false inRecents=true isAvailable=true
lastThumbnail=android.graphics.Bitmap@28bc018 lastThumbnailFile=/data/system_ce/0/recent_images/10570_task_thumbnail.png
stackId=1
hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE isResizeable=true firstActiveTime=1556706445344 lastActiveTime=1556706445344 (inactive for 268s)
* Hist #0: ActivityRecord{d8a470a u0 com.myApp.debug/com.myApp.MainActivity t10570}
packageName=com.myApp.debug processName=com.myApp.debug
launchedFromUid=2000 launchedFromPackage=null userId=0 multiLaunchId=0
app=ProcessRecord{d758be5 11733:com.myApp.debug/u0a187}
Intent { flg=0x10000000 cmp=com.myApp.debug/com.myApp.MainActivity }
frontOfTask=true task=TaskRecord{575db75 #10570 A=com.myApp.debug U=0 StackId=1 sz=1}
taskAffinity=com.myApp.debug
realActivity=com.myApp.debug/com.myApp.MainActivity
baseDir=/data/app/com.myApp.debug-2/base.apk
dataDir=/data/user/0/com.myApp.debug
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f0b002d icon=0x7f0a0000 theme=0x7f0c0006
config={1.0 222mcc50mnc [it_IT] ldltr sw360dp w360dp h580dp 480dpi nrml port finger -keyb/v/h -nav/h suim:4 s.6}
taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
taskDescription: iconFilename=null label="null" color=fff5f5f5
launchFailed=false launchCount=0 lastLaunchTime=-17m43s658ms
haveState=true icicle=Bundle[mParcelledData.dataSize=2808]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_SHOWN
fullscreen=true noDisplay=false immersive=false launchMode=2
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=false lastVisibleTime=-17m42s676ms
resizeMode=RESIZE_MODE_RESIZEABLE
Running activities (most recent first):
TaskRecord{3bd908f #10571 A=org.telegram.messenger U=0 StackId=1 sz=2}
Run #6: ActivityRecord{b96c564 u0 com.myApp.debug/com.myApp.MainActivity t10571}
Run #5: ActivityRecord{75c4f1c u0 org.telegram.messenger/org.telegram.ui.LaunchActivity t10571}
TaskRecord{575db75 #10570 A=com.myApp.debug U=0 StackId=1 sz=1}
Run #4: ActivityRecord{d8a470a u0 com.myApp.debug/com.myApp.MainActivity t10570}
Опять же, это не происходит в других мессенджерах (Сигнал, Whatsapp), в соответствии с режимом запуска singleTask
. Кто-нибудь сталкивался с подобной проблемой? Есть ли обходной путь?