2012-01-21 53 views
0

我一直在寻找周围这个问题的简单的解决方案,但还没有能够找到一个,所以这里有云:呼叫Intent.ACTION_PICK并返回到onActivityResult - 如何?

我有在它tabhost控制单个网页视图的应用程序。如果标签1之后我做的网页视图等一个JavaScript调用,这就是我如何控制这个简单的应用程序的内容。

现在我希望能够推出图像/视频库,并挑选一些媒体,但是这是导致我头疼。它启动了,但是当我选择一些媒体时,应用程序会立即关闭(没有强制关闭,只是消失)。

我已经把一个onActivityResult方法在我的应用程序,但它不会被调用,我不知道为什么。

这是我的一些代码(一切都在同一个活动课):

mTabHost = getTabHost(); 
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Tab1", getResources().getDrawable(R.drawable.iphone)).setContent(R.id.webview)); 
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Tab2", getResources().getDrawable(R.drawable.about)).setContent(R.id.webview)); 
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Tab3", getResources().getDrawable(R.drawable.events)).setContent(R.id.webview)); 
    mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Tab4", getResources().getDrawable(R.drawable.free)).setContent(R.id.webview));  
    mTabHost.addTab(mTabHost.newTabSpec("tab_test5").setIndicator("Tab5", getResources().getDrawable(R.drawable.video)).setContent(R.id.webview)); 
    mTabHost.getCurrentView().setVisibility(View.VISIBLE); 

    mTabHost.setOnTabChangedListener(new OnTabChangeListener() { 
     public void onTabChanged(String arg0) {   
      if(mTabHost.getCurrentTab() == 0) 
      { 
       Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab()); 
       side1(mWebView); 
      } 
      if(mTabHost.getCurrentTab() == 1) 
      { 
       Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab()); 
       side2(mWebView); 
      } 
      if(mTabHost.getCurrentTab() == 2) 
      { 
       Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab()); 
       side3(mWebView); 
      } 
      if(mTabHost.getCurrentTab() == 3) 
      { 
       Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab()); 
       side4(mWebView); 
      } 
      if(mTabHost.getCurrentTab() == 4) 
      { 
       Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab()); 
       side5(mWebView); 
       openStuff(); 
      } 
     }  
    });  



public void openStuff() 
{ 
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); 
    photoPickerIntent.setType("image/*"); 

    startActivityForResult(photoPickerIntent, 1); 

} 


protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) { 
    case 1: 
     if(resultCode == RESULT_OK){ 
      Uri selectedImage = imageReturnedIntent.getData(); 
      String[] filePathColumn = {MediaStore.Images.Media.DATA}; 

      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
      cursor.moveToFirst(); 

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      String filePath = cursor.getString(columnIndex); 
      cursor.close(); 

      Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath); 
     } 
    } 
} 
+0

则应将您链if语句到交换机。 – JoxTraex

回答

0

在此你的问题,你必须写在你的onResume码()方法,而不是onActivityResult。对于管理专业逻辑,您必须在每个选项卡中维护标志,并为所有人编写onResume方法。
如:

@Override 
    protected void onResume() {<br> 
      // TODO Auto-generated method stub<br> 
      super.onResume();<br> 
    } 

我想你知道活动lifecycle

steps : onCreate() - onDestroy()<br> 
onStart()/onRestart() - onStop()<br> 
onResume() - onPause() 
+0

你能提供一个例子吗?我不跟随。 –

+0

设置的方法的onResume一个断点,但给我的图像后的代码不返回的onResume。 –

+0

你说什么?实际上你想要什么? –