我跟着Lukaspili Demo创建了Motor& amp;的MVP架构项目。流程框架集成。我希望在登录之前有两个不同的活动&登录后。我无法获得父活动实例来创建新的Intent(ParentActivity.this,NewActivity.class)。有人遇到过这种情况吗?
答案 0 :(得分:0)
您应该能够以视图的base context
获取活动。
public static Activity getActivity(Context context) {
if(context instanceof Activity) {
return (Activity) context;
} else if(context instanceof ContextWrapper) {
Context baseContext = ((ContextWrapper) context).getBaseContext();
if(baseContext instanceof Activity) {
return (Activity) baseContext;
}
}
Log.e(TAG, "No activity could be found in [" + context + "]");
throw new IllegalStateException("No activity could be found in [" + context + "]");
}