Android activity recreate itself

后端 未结 13 1517
攒了一身酷
攒了一身酷 2021-02-05 07:06

My app normally works just fine, until I face a strange problem on specific device. There are 2 activities in App. After I start ActivityB inside of ActivityA, ActivityA starts

13条回答
  •  太阳男子
    2021-02-05 07:48

    Have you tried changing the launchmode in the Android Manifest? Try adding this to your Activity declaration:

    android:launchMode="singleTask"
    

    Next, try using startActivityForResult, instead of startActivity. This will force Activity A to call its onActivityResult(int, int, Intent) method when Activity B finishes - which may skip this (buggy) call to onCreate. Then, in Activity A, implement the method to do something (such as printing a debug statement):

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        Log.i("Test", "Did this work???");
        //TODO send notification to your server to verify this works?
    }
    

提交回复
热议问题