测试在某些华为机型出现了非常奇怪的一个现象:
启动App,首先启动的是Launcher Activity,正常使用,跳转到一个A Activity,退到后台,然后从手机桌面点击app图标,
这个时候又启动Launcher Activity了

本质就是

Launcher Activity->A Activity->退后台->点击App桌面图标->Launcher Activity
这样看起来就像重新启动了App一样,不能接受。

解决方法:
再Launcher Activity onCreate里面做判断,如果它不是Root Activity,就直接结束。
`
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TAG = "MainActivity";
private static final int REQUEST_CODE = 1001;
private TextView tvCamera;
private TextView tvVersion;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (checkoutActivityError()) {
        Log.e(TAG, "this activity is error just finish it");
        finish();
        return;
    }
    setContentView(R.layout.activity_main);````
}

private boolean checkoutActivityError() {
    // 避免从桌面启动程序后,会重新实例化入口类的activity
    if (!this.isTaskRoot()) {
        Intent intent = getIntent();
        if (intent != null) {
            String action = intent.getAction();
            if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
                return true;
            }
        }
    }
    return false;
}

}
`

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2022-01-20
  • 2021-11-22
  • 2022-12-23
  • 2021-04-23
  • 2021-07-26
猜你喜欢
  • 2022-02-08
  • 2022-03-09
  • 2022-12-23
  • 2021-09-26
  • 2021-04-30
  • 2021-10-11
  • 2021-06-03
相关资源
相似解决方案