在 Camera.PictureCallback 中切换 Activity
我有一个 Camera.PictureCallback 函数,当相机在 android 中拍照时会调用该函数,但我想知道如何访问相机所属的 Activity。这是我的代码:
public Camera camera = null;
Camera.PictureCallback pictureCallbackJpeg = new Camera.PictureCallback()
{
//PictureCallback(Activity a)
//{
//
//}
// An attempt at creating a constructor...
public void onPictureTaken(byte[] data, Camera c)
{
camera.startPreview();
// would like to call activity method
}
}
// Camera Initilisation
camera.takePicture(null, null, pictureCallbackJpeg);
我想切换活动并在这里调用我的主要活动的方法,但我不知道如何执行此操作。有什么想法吗?
I have a Camera.PictureCallback function that gets called when the camera takes a photo in android, but I am wondering how I can access the Activity that the camera is part of. Here is my code:
public Camera camera = null;
Camera.PictureCallback pictureCallbackJpeg = new Camera.PictureCallback()
{
//PictureCallback(Activity a)
//{
//
//}
// An attempt at creating a constructor...
public void onPictureTaken(byte[] data, Camera c)
{
camera.startPreview();
// would like to call activity method
}
}
// Camera Initilisation
camera.takePicture(null, null, pictureCallbackJpeg);
I would like to switch activities and also call a method my main activity here, but I cannot work out how I would do this. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以采用需要在不同类中调用的方法/功能。将它们放在 AndroidUtils.java 之类的东西中。然后,您可以从 Activity 类和 Camera.PictureCallback 调用通用方法。
这样就更干净了&您不必将一个对象传递给另一个对象只是为了调用公共方法。
You could take the methods/functionality that needed to be called in different classes & put them in some thing like AndroidUtils.java. You could then call the common method from the Activity class and the Camera.PictureCallback.
It just is cleaner that way & you don't have to pass an object to another just to call the common method.