2017-06-15 18 views
0

我目前有一個應用程序組成的多個活動,其中之一是一個半透明的。該應用程序有通知,當我點擊它時,我希望它在當前屏幕上的任何位置打開半透明活動。到目前爲止,如果我的應用程序已關閉,則此功能可用,但如果它正在運行並且我的覆蓋活動打開,則我的其他應用程序也處於前臺。我想這樣做只有疊加層出現,一旦用戶按下後,它會回到原來的應用程序。啓動疊加活動而不顯示應用程序的其餘部分

這種模仿谷歌瀏覽器的標籤活動。

我目前推出我的活動通過的PendingIntent:

val intent = Intent(context, WebOverlayActivity::class.java) 
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or PendingIntent.FLAG_ONE_SHOT) 
intent.putExtra(ARG_URL, ...) 
intent.action = System.currentTimeMillis().toString() //dummy action 
val bundle = ActivityOptionsCompat.makeCustomAnimation(context, R.anim.slide_in_right, R.anim.slide_out_right).toBundle() 
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT, bundle) 

這些標誌是什麼,我有,當我在其他地方推出的活動,但他們似乎並沒有影響到這個懸而未決的意圖。如前所述,這項活動是半透明的,並吸引了其他活動。

我覺得我需要將此活動與其他應用程序任務分開,但我也在應用程序中使用了疊加層,不確定是否會影響任何內容。

任何想法?

編輯1:這裏是活動清單

<activity 
    android:name=".WebOverlayActivity" 
    android:theme="@style/AppTheme.Overlay"> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
     <!--other data sources--> 
    </intent-filter> 
</activity> 
+0

我在問題中添加了我的活動清單 –

回答

0

我終於找到一個可行的解決方案。 目標是在新任務中啓動活動,所以我在活動清單中添加了android:launchMode="singleInstance"。令我困惑的是我還需要指定taskAffinity,否則launchMode將被忽略。

我現在可以有效地使用覆蓋來加載其他應用程序中的URL並返回到它,或者從我自己的應用程序中使用它,並使它像其他任何活動一樣。

相關問題