Alex Rivera | Logout

Bug : Theme.Translucent & FLAG_ACTIVITY_REORDER_TO_FRONT

Asked 2012-02-16T10:18:34.040
18

I have an activity with the translucent Theme :

android:theme="@android:style/Theme.Translucent.NoTitleBar"

Also the problem is reproduceable with just this Theme:

<style name="MyTheme" parent="@android:style/Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackground">@null</item>
</style>

This activity is loaded at startup and kept in memory (when I start this activity, I ad the FLAG_ACTIVITY_REORDER_TO_FRONT flag as extra).

Problem : when I start this activity (from the menu), the activity don't show up, nothing happens. But : if I remove the translucent theme : all works fine, the activity is back to front.

Yes onNewIntent() is called.

And if I press back the translucent activity is the one below! But it needs to be the top.

An example being

A ( translucent activity) B C

Stack: A

A startActivity(B)

Stack: A,B

B startActivity(C)

Stack: A,B,C

c startActivity(A) // with flag FLAG_ACTIVITY_REORDER_TO_FRONT

Stack should be: B,C,A

but A is never brought to the front, although its onNewIntent() is called.

Any ideas?

Side notes


Interesting unanswered question: http://groups.google.com/group/android-developers/browse_thread/thread/269c67f6b39cfe45?pli=1


android:launchMode of singleTask or singleInstance are not wanted to be used. These change the backstack and move activities into their own stack. Therefore we don't have A,B,C any more.

Edit
Report

1 Answer

0

Here's my workaround idea. I believe the problem is triggered by requesting a translucent activity in the backstack to be brought to the front. Since we cannot do that, let's just start a new copy of the translucent activity, but instead of completely recreating one from scratch, let's reduce the amount of work by utilizing a fragment.

So if your translucent activity looked like this (copied from MKJParekh's answer):

public class FirstAct extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Button btn = new Button(this);
        btn.setText("First Here Go To Second");
        btn.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                Intent intent = new Intent(FirstAct.this, SecondAct.class);
                startActivity(intent);
            }
        });
        setContentView(btn);
    }
}

We can convert it to something like this:

public class FirstAct extends FragmentActivity {
    private static SavedState mSavedState;
    private FirstFrag mFrag;

    public static class FirstFrag extends Fragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            final Context context = inflater.getContext();
            Button btn = new Button(context);
            btn.setText("First Here Go To Second");
            btn.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(context, SecondAct.class);
                    startActivity(intent);
                }
            });
            return btn;
        }    
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        mFrag = new FirstFrag();
        if (mSavedState != null) 
answered 2013-03-28T09:08:01.810

Your Answer