Is any alternate of Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
Asked Answered
A

1

1

I am creating Two activities as below now when click on button from MainActivity it shows SecondActivity and on click button from SecondActivity shows MainActivity normally but now on click soft back button Device show ANR.

MainActivity buttonClick -> SecondActivity buttonClick -> Soft back click , results ANR.

Is there any workaround?

This issue with Android 4.4.4. I know about this https://code.google.com/p/android/issues/detail?id=63570#c2 issue.

Thanks for any help.

  public class MainActivity extends Activity {
        TextView tv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv = (TextView) findViewById(R.id.textView1);
            tv.setText("Main Activity");
        }

        public void onClickBtn(View view)
        {
            Intent intent = new Intent(this, SecondActivity.class);
            startActivity(intent);
        }

        public void finish(){
            Log.v("MainActivity", "Finish of main activity called");
            super.finish();
        }
    }


    public class SecondActivity extends Activity {
        TextView tv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv = (TextView) findViewById(R.id.textView1);
            tv.setText("Second Activity");
        }

        public void onClickBtn(View view) {
            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(intent);
        }

        public void finish(){
            Log.v("SecondActivity", "Finish of second activity called");
            super.finish();
        }
    }

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="42dp"
        android:onClick="onClickBtn"
        android:text="Button" />


    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:text="@string/hello_world" />

</RelativeLayout>
Albina answered 14/8, 2014 at 11:2 Comment(9)
Post the logcat pleaseTriturable
thanks for help but its not work..(finish is just for show log)Albina
@Triturable : nothing in logcat just show ANR Launcher isn't responding.Albina
is there anything u r doing apart from posted above in activity?Resplendent
try to use in your manifest file, within activity tag android:parentActivityName="your first Activity"Thoracoplasty
What should happen when user presses on back button? Your code is only that much?Triturable
@DIVA no, i just test this code on NEXUS 7 android 4.4.4Albina
@Triturable when user presses on back button just close Activities one by one..Albina
I've got the same behavior with Nexus 7 android version 5.0.2 and Nexus 5 android version 5.0.1.Geothermal
D
1

use intent.setFlags (Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP); the application will not crash.

Dawndawna answered 5/5, 2016 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.