自定义视图调用startActivityForResult [英] Custom View calling startActivityForResult
问题描述
我创造,我合并功能拍照定制的复合视图。
I created custom compound view where I incorporate functionality to take pictures.
我打电话像这样(从视图):
I'm calling it like this (from view):
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity)mContext).startActivityForResult(intent, index);
这部分做工不错。我不知道该怎么做是我怎么落实
This part works good. What I don't know how to do is how do I implement
的onActivityResult
onActivityResult
在我的自定义视图?
或者我应该赶上这个活动里面,比重新路由到我的看法?看起来并不像很不错的解决方案。
Or should I catch this inside Activity and than re-route into my view? Doesn't look like very nice solution..
推荐答案
有没有办法赶上的onActivityResult
从你的观点,只能从活动
。
There is no way to catch onActivityResult
from your view, only from Activity
.
和它不是安全的假设,就是上下文
对象活动
。一般来说,你不应该依赖于这个事实。即使在情况下,似乎是合理的,可欣赏,你仍然应该只使用可用的方法低谷上下文
接口。这是因为你不能predict上的活动
所有的副作用,当你调用活动
特定功能。
And its not safe to assume that's Context
object is Activity
. In general you should not rely on this fact. Even if it seems reasonable in case with views, you still should use only methods available trough Context
interface. That's because your can't predict all side-effects on the Activity
, when you're calling Activity
specific functions.
这篇关于自定义视图调用startActivityForResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!