我创建了一个常见的可重用类的公司为我创造了一些常见的界面元素。
类,需要在一个单一的参数作为在构建体:应用上下文。
的方法之一, ContentClickableRowWithIcon
让您在意图传递给被用作点击动作。
继承人的完整方法声明:
public LinearLayout ContentClickableRowWithIcon(Drawable icon, String title, Intent i, final Boolean chooser)
去年属性有在onClickEvent用来确定是否调用选配或者只是去直接进入的意图。
public LinearLayout ContentClickableRowWithIcon(Drawable icon, String title, Intent i, final Boolean chooser) {
LinearLayout ll = new LinearLayout(mContext);
// .. LinerLayout construction, has nothing to do with the action
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this is apparently getting ignored... (ps: i've tried i.setFlags as well)
final Intent intent = i;
ll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(chooser)
mContext.startActivity(Intent.createChooser(intent, "Complete With...")); // crashes here with: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
else
mContext.startActivity(intent); // this works fine
}
});
return ll;
}
正如在评论中提到的,只要我不提供使用一个选择器的能力,一切工作正常(一切都在这个名单得到了新的有效标志,即时通讯深知这一点,并清理时,这个问题想通了)
我做的那一刻,抛出该异常: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
我已经江郎才尽了?
/// ::编辑值得注意的,在调试,标志在Intent属性设置为268435456
与addFlags和268435456
用setFlags,当达到使用目的在onclick行动的时候了