Shadow icon indicating copy to clipboard operation
Shadow copied to clipboard

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.

Open shifujun opened this issue 3 years ago • 4 comments

改为这个方法之后调起activity会报
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

最初由 @hzbhzb 在 https://github.com/Tencent/Shadow/issues/640#issuecomment-948563975 发布

有复现问题的代码吗?在sample上复现一下,push上来看看。要不就算我复现并修复了,也可能不是你说的情况。

shifujun avatar Oct 21 '21 12:10 shifujun

复现的路径也是跟因为attachBaseContext 那里替换掉了context。跟https://github.com/Tencent/Shadow/issues/640#issuecomment-948563975 这个的复现路径一样。

hzbhzb avatar Oct 21 '21 13:10 hzbhzb

复现的路径也是跟因为attachBaseContext 那里替换掉了context。跟https://github.com/Tencent/Shadow/issues/640#issuecomment-948563975 这个的复现路径一样。

但是你那个issue就没给出实际的代码啊。你以为你说的很清楚,实际上有很多种写法的。我的修复提交里已经增加了我可以复现的测试代码。修复前后是能对比复现和不复现的。

shifujun avatar Oct 21 '21 15:10 shifujun

嗯,我按照你那个修复提交的测试代码跑了一下,demo 里面调起activity 没有报这个错误,我再调试下看是哪块写错了。

hzbhzb avatar Oct 22 '21 02:10 hzbhzb

package com.tencent.shadow.sample.plugin;

import android.app.Activity; import android.content.Context; import android.content.res.Configuration;

public class BaseActivity extends Activity { @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(getConfigurationContext(newBase)); }

private static Context getConfigurationContext(Context context) {
    Configuration configuration = context.getResources().getConfiguration();
    configuration.fontScale = 1;
    return context.createConfigurationContext(configuration);
}

}

基于1196的分支,在插件的所有Actiivty都继承这个BaseActivity 的话,会报Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag这个错,原因应该和640一样。插件业务除了不调用return context.createConfigurationContext(configuration);外,还有别的解决方法吗?

shuhui-sh avatar Sep 22 '23 09:09 shuhui-sh