0
問題:活動1有圖像路徑,當活動1通過意圖發送圖像文件時,活動2具有到不同圖像的不同路徑。圖像路徑不覆蓋
代碼活動1:
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
imageFile = new File(outputFileUri.getPath());
} else if (requestCode == UPLOAD_REQUEST && resultCode == RESULT_OK) {
//Get the data back from the request in URI format (Path to file).
selectedImage = data.getData();
imageFile = new File(getRealPathFromURI(selectedImage));
} else if (resultCode == RESULT_CANCELED) {
return;
}
Intent menuIntent = new Intent(getApplicationContext(), MenuActivity.class);
menuIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
menuIntent.putExtra("username", username);
menuIntent.putExtra("latitude", latitude);
menuIntent.putExtra("longitude", longitude);
menuIntent.putExtra("imageFile", imageFile);
Log.d("ACTIVITY1 image", imageFile.getPath());//THIS LOG BELOW!!
try{
startActivity(menuIntent);
finish();
}
catch(ActivityNotFoundException e){
e.printStackTrace();
menuIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
startActivity(menuIntent);
finish();
}
}
原因在意圖嘗試捕捉是被用於從該一個不同的使用開此酶活性。 代碼活動2:
...
@Override
public void onStart() {
super.onStart();
Bundle extras = getIntent().getExtras();
if (extras != null) {
username = extras.getString("username");
latitude = extras.getDouble("latitude");
longitude = extras.getDouble("longitude");
if(extras.get("imageFile") != null){
File imageFile = (File) extras.get("imageFile");
Log.d("ACTIVITY2 image", imageFile.getPath());//THIS LOG BELOW!!
toastContext = getApplicationContext();
params = new ArrayList();
params.add("upload");
params.add(username);
params.add(imageFile);
uploadImage = new UserFunctions(this);
uploadImage.execute(params);
}
}
}
有經由POST將文件發送到服務器並返回JSON,以形成根據所述響應它的通知和更新的的AsyncTask。那裏沒有問題。 如果用戶登錄,則加載活動2,如果不是,則在用戶登錄時稍後調用活動2。 當活動2通過buttonListener加載活動1,然後活動1要麼拍照時,選擇一個文件。當活動1已經決定時,它立即再次加載活動2,在意圖中傳遞新的imageFile。當活動2加載時,它將請求發送給服務器。返回 日誌是: 第一次的圖像通過POST發送:
DEBUG/ACTIVITY1 image(15559): /storage/emulated/0/DCIM/Camera/IMG_20130215_193022.jpg
然後傳遞通過意向活動2 ...
DEBUG/ACTIVITY2 image(15559): /storage/emulated/0/DCIM/Camera/IMG_20130215_193022.jpg
第二次,選擇不同的圖像或服用後新的照片:
DEBUG/ACTIVITY1 image(15559): /storage/emulated/0/DCIM/Camera/IMG_20130214_212205.jpg
然後傳遞通過意向活動2 ...
DEBUG/ACTIVITY2 image(15559): /storage/emulated/0/DCIM/Camera/IMG_20130215_193022.jpg
如果有ASyncTask/onPostExecute請求,我會發布它!
謝謝!
編輯:新增Android清單澄清活動:
<activity android:name=".ACTIVITY1" android:label="@string/app_name"
android:screenOrientation="portrait"/>
<activity android:name=".ACTIVITY2"
android:label="@string/app_name"
android:parentActivityName=".ACTIVITY1"
android:excludeFromRecents="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ACTIVITY1"/>
</activity>