English 中文(简体)
主动性研究没有在缩写小组工作吗?
原标题:OnActivityResult is not working in TabActivityGroup?

我使用 Tab 活动作为主要活动, 它有 4 个制表符。 一个制表符是活动组, 有 3 个按钮 。 每个按钮都是一个活动 。 我在其中一项活动中使用相机 。 我知道它的工作, 因为我在存储卡中检查了保存的图像, 但是它没有使用 OnactutionAgress () 方法 。

这是要显示内容View

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.enter_expenses, null);
    this.setContentView(viewToLoad);            

此代码用于拍摄图像

             dbimgguid = UUID.randomUUID();
             imagename =dbimgguid.toString();
             Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
             photo = new File(Environment.getExternalStorageDirectory(), "Expenses"+imagename+".jpg");
             intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photo));
             imageurl = Uri.fromFile(photo); 
             startActivityForResult(intent, CAMERA_RECEIPTREQUEST); 

这是活动结果

     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
     super.onActivityResult(requestCode, resultCode, data);  
     System.out.println(requestCode);
     System.out.println(resultCode);
     switch(requestCode)
     {
     case CAMERA_RECEIPTREQUEST:  
         if(resultCode== Activity.RESULT_OK)
         {
         //Toast.makeText(this, "Receipt Image Saved", Toast.LENGTH_SHORT).show();
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inSampleSize = 8;
         //ImageView jpgView = (ImageView)findViewById(R.id.imageView1);
         Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);  
         String image = "Expenses"+imagename+".jpg"; 
         Intent imagepass = new Intent(ExpensesActivity.this,ReviewReceiptImage.class);
         imagepass.putExtra("receipt", receipt);
         imagepass.putExtra("imagename", image);
         startActivityForResult(imagepass, CAMERA_CONFIRMRECEIPT); 
         Toast.makeText(this, "Receipt Image Saved", Toast.LENGTH_SHORT).show();
         }

     case CAMERA_CONFIRMRECEIPT:

         Toast.makeText(this, "Receipt Image Saved", Toast.LENGTH_SHORT).show();
         if(resultCode == CAMERA_CONFIRMRECEIPT)
         {
             take_receipt.setEnabled(false);
             take_receipt.setVisibility(View.GONE);
             show_receipt.setEnabled(true);
             show_receipt.setVisibility(View.VISIBLE);
         } 
         break;
     }
 }

谢谢你的帮忙 伙计们

最佳回答

我的问题解决了,请见我下面的答案

我终于想通/记得, 问题是因为Android只允许一个嵌巢层的亚活性..., 即亚活性, 无法嵌巢子活性。 要解决这个问题:

call getParent().startActivityForResult() from your sub-activity your parent (the activitygroup) will be able to handle the onActivityResult. So I created a subclass of ActivityGroup and handled this onActivityResult. You can re-route that result back to the sub-activity if you need to. Just get the current activity by getLocalActivityManager().getCurrentActivity() . My sub-activities inherit from a custom activity so I added a handleActivityResult(requestCode, resultCode, data) in that subclass for the ActivityGroup to call.

以精确代码回答上述问题

< 强度 > 活动组- gt; 准活动 & gt; on 积极性Result- gt; 活动组( 积极性Result) - gt; 辅助活动组( 积极性Result)

这是活动组类, 您必须在其中定义所有子活动 的“ 活动结果”,

@Override
public void onActivityResult(int requestCode,int resultCode, Intent data)
{

         switch(requestCode)
            {

            case CAMERA_RECEIPTREQUEST:   
            if(resultCode == Activity.RESULT_OK)
            {
            ExpensesActivity activity = (ExpensesActivity) getLocalActivityManager().getCurrentActivity();
            activity.onActivityResult(requestCode, resultCode, data);
            }
            break;

            case CAMERA_CONFIRMRECEIPT:
            ExpensesActivity activity1 = (ExpensesActivity) getLocalActivityManager().getCurrentActivity();
            activity1.onActivityResult(requestCode, resultCode, data);   
            }

        }

在子活动中,您必须设置以下视图

    View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.enter_time, null);
    this.setContentView(viewToLoad);

然后在关于活动成果的分活动中()

    @Override
    public void onActivityResult(int requestCode,int resultCode, Intent data)
    {
     //Some Code
    }
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签