【问题标题】:Correct way to restart activity after phone call ends电话结束后重新开始活动的正确方法
【发布时间】:2016-11-30 09:46:37
【问题描述】:

这两种方法都有效,但我不确定哪个是最好的代码,以便它每次都适用于 API 17-25。我的应用程序依赖于我通过 PhoneStateListener 进行的通话结束后打开的活动。

我已经看到推荐的两种方式,如果这是一个不好的问题,请见谅!

Intent restart = mContext.getPackageManager().
            getLaunchIntentForPackage(mContext.getPackageName());
    restart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    restart.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mContext.startActivity(restart);

    Intent intent = new Intent(mContext, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    mContext.startActivity(intent);

【问题讨论】:

    标签: java android service phone-state-listener


    【解决方案1】:

    你应该使用Activity类的recreate()方法来重启Activity,而不是这两种方法

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多