安卓:捕捉活动的回报 [英] Android: Capturing the return of an activity

查看:155
本文介绍了安卓:捕捉活动的回报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于推出新的活动的问题。它归结为这一点。 我有一个观点3个标签

I have a question regarding launching new activities. It boils down to this. I have 3 tabs on a view

A) contains gMap activity
 B) camera activity
 C) some random text fields.

要求是应用在人像模式下运行。

Requirement is that the application runs in Portrait mode.

所有3个标签按预期工作瓦特/异常的摄像头preVIEW面(B)的。它被旋转90度。他们只有这样,才能使正确的是设置应用程序,以景观会抛出我所有的标签四周,是pretty的太多不切实际的。

All 3 tabs work as expected w/ the exception of the Camera Preview Surface (B). It is rotated 90 degrees. They only way to make it correct is to set the app to landscape which throws all my tabs around, and is pretty much unworkable.

我的解决办法是这样的:替换

My solution is this : replace

我的相机活动与经常性活动是空的瓦特/异常

my camera activity with a regular activity that is empty w/ the exception of

Intent i = new Intent(this,CameraActivity.class);
    startActivity(i);

这将启动我的CameraActivity。这工作正常。我不得不做一个线性布局,包括看起来像真正的选项卡3张图片,这样我就可以尝试和模仿标签的操作而旋转屏幕为横向,保持视觉效果的肖像。 用户可以点击的图像(按钮),一个用于显示下一个标签。这是我的问题。它应该退出我的摄像头的活动回到一个标签,它应该是PTED单击desiered选项卡从我的图像间$ P $的'空白的活动。

This launches my CameraActivity. And that works fine. I had to do a linear layout and include 3 images that look like real tabs, so I can try and mimic the operation of the tabs while rotating the screen to landscape and keep the visuals as portrait. The user can click one of the images(buttons) to display the next tab. This is my issue. It should exit my 'camera activity' returning to the 'blank activity' in a tab, where it should be interpreted to click the desiered tab from my image.

更主要的是,当它返回时,它返回一个空(黑色)第一个标签下(因为它是空)。我怎样才能获取返回的事件回调用该活动的页面,然后看他们执行什么操作?

The main thing is, when it returns, it returns to a blank (black) page under a tab (because it is 'empty'). How can I capture the return event back to the page that called the activity, and then see what action they performed?

我可以设置一个onclicklistener,我可以给假标签(图像)被点击退出相机活动进行回应。退出时,标签应该更新,这样就是你回来。有什么建议?

I can set an onclicklistener where I can respond to the fake tabs (images) being clicked to exit out of the camera activity. On exit, the tab should update so that is where you return. any Suggestions?

谢谢

推荐答案

我将重点讨论回答如何解决您的workround,这样它的行为,只要你想。

I'll focus on answering how to resolve your workround so that it behaves as you want.

要捕获在一个又一个的活动中进行的操作需要三个步骤。

To capture actions performed on one Activity within another requires three steps.

使用 startActivityForResult ,而不是 startActivity 的启动辅助活动(你的摄像头的活动)作为子活动。

Launch the secondary Activity (your 'camera Activity') as a subactivity by using startActivityForResult instead of startActivity.

Intent i = new Intent(this,CameraActivity.class);    
startActivityForResult(i, STATIC_INTEGER_VALUE);

在子活动(摄像头的活动),而不仅仅是关闭活动,当用户点击不同的标签图像,你需要创建一个新的意图,并包括选项卡的索引,当您使用返回到父应用程序,以显示其它功能捆绑。要调用完成关闭相机活动之前回来把它传递给父调用的setResult

Within the subactivity (camera Activity), rather than just closing the Activity when a user clicks the different tab image, you need to create a new Intent and include the index of the tab to display when you return to the parent app using the extras bundle. To pass it back to the parent call setResult before calling finish to close the camera Activity.

resultIntent = new Intent(null);
resultIntent.putExtra(PUBLIC_STATIC_STRING_IDENTIFIER, tabIndexValue);
setResult(Activity.RESULT_OK, resultIntent);
finish();

最后一步是在调用活动,覆盖 onActivityResult 来侦听来自摄像头的活动回调。获得额外的从返回意向,以确定应显示的标签的索引

The final step is in the calling Activity, override onActivityResult to listen for callbacks from the camera Activity. Get the extra from the returned Intent to determine the index of the tab you should be displaying.

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) {     
  super.onActivityResult(requestCode, resultCode, data); 
  switch(requestCode) { 
    case (STATIC_INTEGER_VALUE) : { 
      if (resultCode == Activity.RESULT_OK) { 
      int tabIndex = data.getIntExtra(PUBLIC_STATIC_STRING_IDENTIFIER);
      // TODO Switch tabs using the index.
      } 
      break; 
    } 
  } 
}

这篇关于安卓:捕捉活动的回报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆