scottyab
scottyab

Reputation: 24039

Activity transparent background of home screen not last activity

I'm launching an Activity from the android.intent.action.CALL intent. I'd like to show a layout similar to dialog with progress with transparent background (while i do processing before handing over to native dialer). But behind background that is visible should be the home screen.

At the moment is the activity loads ok and the background outside of the desired loading dialog is transparent but instead of the home screen in the background the last application screen/activity is displayed.

How can I force the background behind my transparent to be the home screen?

Upvotes: 3

Views: 6919

Answers (6)

Osama Ibrahim
Osama Ibrahim

Reputation: 1021

use this Theme in your style

<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>

Upvotes: 0

user1070256
user1070256

Reputation:

In order to do so, just set the android theme in your manifest file to 'Theme.Wallpaper'

i.e: <activity android:theme="@android:style/Theme.Wallpaper" />

Also make sure you set a transparent background for your activity. For example, I have defined a translucent black color that I use as background for my activity:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="translucent_black">#CF000000</color>
</resources>

Upvotes: 9

Dori
Dori

Reputation: 18413

try launchMode="singleInstance" in your manifest ;)

Upvotes: 0

Phil
Phil

Reputation: 36289

One option (which is highly not recommended) is to kill all other visible processes. This code will take care of it:

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.util.Log;

public class Test {
public Test(Context c){
    ActivityManager am = (ActivityManager)c.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> list = am.getRunningAppProcesses();
    for (int i=0; i<list.size(); i++){
        Log.i("apps info", list.get(i).processName +"; PID=" + list.get(i).pid);
        if(list.get(i).importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE){
            android.os.Process.killProcess(list.get(i).pid);
        }
    }
  }
}

Like stated above, this should be avoided. This type of code is best reserved for a Task manager app.

Upvotes: 0

Matt Gaunt
Matt Gaunt

Reputation: 9821

Firstly you shouldnt be altering the activity stack outside of your application, big no no.

Secondly, receiving an broadcast will result in other applications being run in the foreground some of the time (other than the home screen). So you'll have to just accept that will be the case.

You can either display a dialog and use the dialog theme so the background activity, while still there is obscured slightly, or go the other way and just show up a full activity.

Upvotes: 0

CaseyB
CaseyB

Reputation: 25058

You can't force it to be the Home Screen, but you can grab the current wallpaper and use that as your background.

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    Drawable wallpaper = WallpaperManager.getInstance(this).getDrawable();
    // Set wallpaper to the background of the root view
}

Upvotes: 0

Related Questions