简体   繁体   English

Android在onNewIntent中从Camera Intent获得结果

[英]Android get result from Camera Intent in onNewIntent

I have an Activity with android:launchMode="singleInstance" . 我有一个与android:launchMode="singleInstance" I want launch camera from this and then process result, but startActivityForResult doesn't work with singleInstance. 我要从中启动相机,然后处理结果,但是startActivityForResult不适用于singleInstance。 So maybe it's possible to get result from camera using onNewIntent method? 因此,也许可以使用onNewIntent方法从摄像机获取结果? If it's possible, how can I implement this? 如果有可能,我该如何实施?

You might want to look at both singleTask and singleInstance. 您可能要同时查看singleTask和singleInstance。

singleTask: singleTask:

The system creates a new task and instantiates the activity at the root of the new task. 系统创建一个新任务,并在新任务的根目录处实例化活动。 However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance. 但是,如果活动的实例已经存在于单独的任务中,则系统将通过对其onNewIntent()方法的调用将意图路由到现有实例,而不是创建新实例。 Only one instance of the activity can exist at a time. 一次只能存在一个活动实例。

Note: Although the activity starts in a new task, the Back button still returns the user to the previous activity. 注意:尽管活动在新任务中开始,但是“后退”按钮仍使用户返回上一个活动。

singleInstance: singleInstance:

Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. 与“ singleTask”相同,除了系统不会将任何其他活动启动到保存实例的任务中。 The activity is always the single and only member of its task; 活动始终是其任务的唯一且唯一的成员。 any activities started by this one open in a separate task. 由该任务开始的任何活动都在单独的任务中打开。

Note: That means, the activity with launch mode is always in a single activity instance task. 注意:这意味着,具有启动模式的活动始终在单个活动实例任务中。 This is a very specialized mode and should only be used in the applications that are implemented entirely as one activity. 这是一种非常专业的模式,仅应在完全作为一个活动实现的应用程序中使用。

You could try something like this 你可以尝试这样的事情

protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Uri uri = intent.getData();
    if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {

        try {
            //load image goes 

         } catch (Exception e) {
             Log.e(TAG, e.getMessage(), e);
         }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM