正方形流动导航

时间:2016-08-17 11:21:22

标签: android dagger-2 flow

我跟着Lukaspili Demo创建了Motor& amp;的MVP架构项目。流程框架集成。我希望在登录之前有两个不同的活动&登录后。我无法获得父活动实例来创建新的Intent(ParentActivity.this,NewActivity.class)。有人遇到过这种情况吗?

1 个答案:

答案 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 + "]");
}