2011-09-20 78 views
2

我的应用程序的主要活动是首选项页面。这是用户单击应用程序图标时显示的内容。我还有一项服务,可以发送用户状态栏通知,并且可以在屏幕上显示半透明覆盖图。我遵循this发布创建我的透明活动,所有这些工作。Android独立透明活动

问题在于,无论何时,我都会显示半透明活动,应用程序的主窗口(首选项页面)在其后面可见。也就是说,半透明覆盖图显示在当前正在运行的任何其他应用程序的顶部。

我该怎么做才能使半透明活动出现时,我的应用程序中没有其他活动可见?

这是我的主要活动在AndroidManifest.xml中定义:

<activity android:name=".AppPreferences" android:label="@string/app_name"> 
    <intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 

我也有半透明的叠加,它使用从Theme.Translucent派生的自定义主题:

<activity android:name=".AppPopupActivity" android:theme="@style/Theme.SemiTransparent"> 
    <intent-filter> 
     <action android:name="com.app.HIDE_POPUP"></action> 
    </intent-filter> 
</activity> 

这里是布局用于半透明覆盖物:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

    <RelativeLayout android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" > 

     <Button android:text="@string/button_done" 
       android:id="@+id/doneButton" 
       android:layout_alignParentRight="true" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
     </Button> 
    </RelativeLayout> 
</RelativeLayout> 

而服务:

<service android:name="AppService"> 
    <intent-filter> 
    <action android:name="com.app.AppService" /> 
    </intent-filter> 
</service> 

要显示透明的活动我运行的服务如下:

Intent intent = new Intent(this, AppPopupActivity.class); 
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
this.startActivity(intent); 

感谢您的帮助

+2

这不就是透明的定义是什么?你可以看到它背后的任何东西。 – nhaarman

+3

我同意尼克,你没有提到你想要发生什么。 – dmon

+0

你们都错了,(我想)这个人有他的活动堆栈的问题,什么摆脱所有的堆栈,并推出他的透明的东西;-) 查看答案。 –

回答

5

虽然Profete162波纹管的答案没有工作,这使我在正确的方向。更多的阅读和实验后,我认为正确的答案是改变的主要活动的launchMode为“singleInstance”如下:

<activity android:name=".AppPreferences" android:label="@string/app_name" 
      android:launchMode="singleInstance"> 
    <intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 
+1

,为我工作,谢谢! – Shatazone

0

“问题是,曾经一次我显示我的半透明的活动,应用程序的主窗口(首选项页面)在它后面可见。“

你的问题是你有你的设置活动,并在它上面,TransparentACtivity。他们是在一个“堆栈”

当你打电话给你的通知,transparentActivity进来活动堆栈的前面(=设置)

如果你想看看会发生什么“的背后”的transparentACtivity,你必须摆脱的筹码是这样的:

尝试增加FLAG_ACTIVITY_CLEAR_TOP:

这次发射模式也可以用来结合良好的效果与 FLAG_ACTIVITY_NEW_TASK:如果用于启动任务的根系活力, 它会将该任务的任何当前正在运行的实例带到前台,然后将其清除为其根状态。例如,在从通知 管理器启动活动时,这尤其有用,例如: 。

所以你的代码发动是:

Intent intent = new Intent(this, A.class); 
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 
+0

非常感谢您的回答。虽然它没有像现在这样工作,但我相信它让我朝着正确的方向前进。 – oneself