I tried using this Flag in setFlags from tutorial but its deprecated, what do i do

时光毁灭记忆、已成空白 提交于 2019-12-24 14:55:23

问题


FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET is deprecated; so what should I use?

private Intent createShareForecastIntent() {

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mforecastStr + FORECAST_SHARE_HASHTAG);
    return shareIntent;


}

回答1:


Quoting the documentation:

As of API 21 this performs identically to FLAG_ACTIVITY_NEW_DOCUMENT which should be used instead of this.

Since both symbols have the same numerical value (0x00080000), it does not really matter which one you use in terms of runtime behavior. If your compileSdkVersion is 21 or higher, switch to FLAG_ACTIVITY_NEW_DOCUMENT




回答2:


See here (Intent)

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
        }


来源:https://stackoverflow.com/questions/33179042/i-tried-using-this-flag-in-setflags-from-tutorial-but-its-deprecated-what-do-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!