2014-09-24 107 views
1

我目前正在添加一個科爾多瓦插件來啓動我自己的自定義相機應用程序。我還包括Aviary做一些照片編輯。現在我最大的問題是我不知道如何從活動返回(3)回活動(1),我需要能夠訪問和調用:如何從第三個子活動調用父活動

this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); 

我已經通過計算器上的很多職位搜索和許多博客。我遵循了我見過的用於回到父母活動的對流,但是我沒有看到從A→B→C→A的任何地方。我現在的代碼在下面發佈。目前我能夠從Aviary上去 - >到我的第二個活動(相機預覽),但是我爲什麼不能進一步上升到一個級別。

難道不可能走上那麼遠嗎?
是不是可以添加完成();要儘可能早地回到你想要的位置?

我的執行方法根據科爾多瓦文檔駐留在活動1:

(1)CordovaPlugin

public class Aviary extends CordovaPlugin{ 

    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 
      this.callbackContext = callbackContext; 

      Intent i = new Intent(cordova.getActivity(), CameraActivity.class); 
      this.cordova.startActivityForResult((CordovaPlugin) this, i, (CAMERA + 1) * 16 + returnType + 1); 


    public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
     logger.i("ACTIVITYRESULT - returned from cameraActivity, now in aviary"); 

     if (resultCode == Activity.RESULT_OK && requestCode == CameraConstants.FROM_CAMERA_TO_EXECUTE) 
      // I need this to launch with the uri data contained within the intent 
      //build json array here 
      this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); 

我的第二活性,然後用相機預覽開始。捕獲圖像後,我會使用捕獲的位圖啓動一項活動,並在屏幕上顯示選項,以便發佈圖像或使用鳥舍進行編輯。

(2)CameraActivity:啓動postcapture屏幕

Intent intent = new Intent(context, PostCaptureActivity.class); 
intent.putExtra(CameraConstants.URI, path); 
intent.putExtra("requestCode", CameraConstants.FROM_SAVEIMAGETASK_TO_POSTCAPTURE); 
intent.putExtra(CameraConstants.SOURCE, CameraConstants.SOURCE_CAMERA); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivityForResult(intent, CameraConstants.FROM_SAVEIMAGETASK_TO_POSTCAPTURE); 

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

    if (requestCode == CameraConstants.FROM_POSTCAPTURE_TO_PREVIEW) 
    { 
     logger.i("ACTIVITYTHREAD - inCameraActivity about to call finish"); 
     Intent intent= new Intent(); 
     setResult(RESULT_OK, intent); 
     //intent.putExtra("uri", data.getData()); 
     intent.putExtra("requestCode", CameraConstants.FROM_CAMERA_TO_EXECUTE); 
     finish(); 
    } 

活動3:PostCaptureActivity(啓動百鳥)

private void setupAviaryIntent() { 
    logger.i("Launching Aviary"); 
    Intent intent = new Intent(PostCaptureActivity.this, FeatherActivity.class); 
    intent.setData(Uri.parse(uri)); 
    intent.putExtra("requestCode", CameraConstants.LAUNCH_AVIARY); 
    intent.putExtra("output-quality", 100); 
    intent.putExtra("output-format", Bitmap.CompressFormat.JPEG.name()); 
    intent.putExtra("effect-enable-fast-preview", true); 
    intent.putExtra("tools-list", new String[]{"CROP", "EFFECTS", "ADJUST", "ENHANCE", 
      "DRAWING", "TEXT", "SHARPNESS", "BRIGHTNESS", "CONTRAST", 
      "BLEMISH", "SATURATION", "RED_EYE", "WHITEN", "COLORTEMP"}); 
    startActivityForResult(intent, CameraConstants.LAUNCH_AVIARY); 
} 


@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    super.onActivityResult(requestCode, resultCode, data); 
    /** FROM: Aviary TO: Preview*/ 
    if(resultCode == RESULT_OK && requestCode == CameraConstants.LAUNCH_AVIARY) 
    { 
     logger.i("in PostCaptureActivity, should go back to CameraActivity"); 
     Uri uri = data.getData(); 
     Intent intent = new Intent(); 
     setResult(RESULT_OK, intent); 
     intent.putExtra("requestCode", CameraConstants.FROM_POSTCAPTURE_TO_PREVIEW); 
     intent.putExtra("uri", uri); 
     finish(); 
    } 
} 

我所尋找的是兩種方式從活動3和返回去回到父活動(1)或者我如何跳回到活動的一些例子,並且能夠用我的圖片信息運行sendPluginResult方法。

編輯: 因此,事實證明,我無法在完成()後返回到上一個活動的原因;是因爲我在其中一個意圖中添加了國旗。重讀文檔後,我意識到錯誤是什麼。刪除這條線後,我能夠按預期工作。

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

回答

0

沒有歷史標誌在你的第二個活動。

+0

這在技術上回答了關於從活動3返回到1的問題。謝謝! – ViciDroid 2014-09-25 15:35:30

0

像下面設置標誌,這將清除活動Activity3和活性1

使用之間
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
       | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
相關問題