我有一个问题,我有三个片段正在从未显示的 onActivityResult 函数运行。这很奇怪,因为片段正在运行并且我能够与它们交互(例如,我可以单击后退按钮,片段将出现然后展开)但它们不显示。我已经测试了 onActivityResult 函数之外的片段(因此在单击按钮时运行它们)并且它们工作正常。另一个奇怪的事情是这个问题只发生在平板电脑上,它在手机上运行良好。
下面是 onActivityResult 代码:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("ACTIVITY RESULT");
System.out.println("REQUEST CODE >>>>> " + requestCode);
if (requestCode == webview) {
// if (resultCode == RESULT_OK) {
System.out.println("RESULT WEBVIEW");
System.out.println(data.getStringExtra("URL"));
Bundle args = new Bundle();
args.putString("URL", data.getStringExtra("URL"));
args.putString("List Name", currentList);
args.putInt("List Position", pos);
URLFragment urlFrag = new URLFragment();
urlFrag.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.setCustomAnimations(R.anim.in_from_right,
R.anim.out_from_left);
System.out.println("FRAG CONTAINER >>>> "
+ findViewById(R.id.fragment_container));
System.out.println("ARTICLE FRAG >>>> "
+ findViewById(R.id.article_fragment));
if (findViewById(R.id.fragment_container) != null) {
transaction.add(R.id.fragment_container, urlFrag,
"URL Fragment");
transaction.addToBackStack(null);
} else {
transaction.add(R.id.article_fragment, urlFrag, "URL Fragment");
}
transaction.commit();
// }
// if (resultCode == RESULT_CANCELED) {
// // Write your code if there's no result
// System.out.println("CANCELED WEBVIEW");
// }
} else if (requestCode == camera) {
if (resultCode == RESULT_OK) {
System.out.println("RESULT CAMERA");
System.out.println(data.getData());
if (data.getData().toString().contains("picasa")) {
System.out.println("UNABLE TO LOAD IMAGE");
Toast.makeText(
getApplicationContext(),
"We are unable to load this image, please select a different one",
Toast.LENGTH_LONG).show();
} else {
if (getSupportFragmentManager().findFragmentByTag(
"Image Fragment") == null) {
GatherGalleryImages gatherImage = new GatherGalleryImages();
Uri selectedImageUri = data.getData();
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(selectedImageUri,
projection, null, null, null);
String selectedImagePath = gatherImage.getPath(cursor);
System.out.println(selectedImagePath);
Bundle args = new Bundle();
args.putString("List Name", currentList);
args.putInt("List Position", pos);
args.putString("Image Location", selectedImagePath);
CameraItemFragment newFragment = new CameraItemFragment();
newFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.setCustomAnimations(R.anim.in_from_right,
R.anim.out_from_left);
if (findViewById(R.id.fragment_container) != null) {
transaction.add(R.id.fragment_container,
newFragment, "Image Fragment");
transaction.addToBackStack(null);
transaction.commit();
} else {
transaction.add(R.id.article_fragment, newFragment,
"Image Fragment");
// transaction.addToBackStack(null);
transaction.commit();
}
}
}
}
if (resultCode == RESULT_CANCELED) {
// Write your code if there's no result
System.out.println("CANCELED CAMERA");
}
} else if (requestCode == IntentIntegrator.REQUEST_CODE) {
if (resultCode != RESULT_CANCELED) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(
requestCode, resultCode, data);
if (scanResult != null) {
String upc = scanResult.getContents();
// put whatever you want to do with the code here
System.out.println("UPC >>>> " + upc);
Intent mainIntent = new Intent(MainActivity.this,
Webview_Activity.class);
mainIntent.putExtra("upc", upc);
mainIntent.putExtra("listName", currentList);
MainActivity.this.startActivityForResult(mainIntent, 1);
}
}
} else if (requestCode == cam) {
System.out.println("CAMERA INTENT 0");
if (resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
// CALL THIS METHOD TO GET THE URI FROM THE BITMAP
Uri tempUri = getImageUri(getApplicationContext(), photo);
// CALL THIS METHOD TO GET THE ACTUAL PATH
File finalFile = new File(getRealPathFromURI(tempUri));
String selectedImagePath = finalFile.getAbsolutePath();
Bundle args = new Bundle();
args.putString("List Name", currentList);
args.putInt("List Position", pos);
args.putString("Image Location", selectedImagePath);
CameraItemFragment newFragment = new CameraItemFragment();
newFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.setCustomAnimations(R.anim.in_from_right,
R.anim.out_from_left);
if (findViewById(R.id.fragment_container) != null) {
transaction.add(R.id.fragment_container, newFragment,
"Image Fragment");
transaction.addToBackStack(null);
transaction.commit();
} else {
transaction.add(R.id.article_fragment, newFragment,
"Image Fragment");
// transaction.addToBackStack(null);
transaction.commit();
}
}
if (resultCode == RESULT_CANCELED) {
// Write your code if there's no result
}
} else if (resultCode == RESULT_CANCELED) {
}
}
}
这是我遇到的最奇怪的问题之一,如果有人可以提供帮助,那就太好了。