when i start Camera
intent, i noticed onActivityResult
is called before onResume
in fragment
lifecycle.
I also noticed onActivityResult
is called after onStart
.
But here's the strange part: i have variable fileUri == "some image path". This variable is
see logCat
12-03 14:39:42.418: D/Fragment1(29220): onStart fileUri: file:///mnt/sdcard/OPS_IMAGES/IMG_20121203_143933.jpg
12-03 14:39:42.463: W/PhoneWindow(29220): Previously focused view reported id 2131034140 during save, but can't be found during restore.
12-03 14:39:42.463: D/Fragment1(29220): onActivityResult fileUri is NULL!!!
12-03 14:39:42.468: D/Fragment1(29220): onResume fileUri: file:///mnt/sdcard/OPS_IMAGES/IMG_20121203_143933.jpg
Worst part is, this only happens 50% of the time. Another 50% onActivityResult can access fileUri value without problem...
How am i supposed to debug this?
NOTE: For the sake of simplicity, i didnt include code of my onResume, onStart, onActivityResult methods. They are just basic methods with variable check and log call. If needed, i will edit question and add these methods.
NOTE2: i am using google support library to support fragments on older API versions.
To get the result in your fragment make sure you call startActivityForResult(intent,111); instead of getActivity(). startActivityForResult(intent,111); inside your fragment. @StErMi Make sure you call startActivityForResult() and not getActivity(). startActivityForResult() from your fragment.
Each Fragment instance has its own lifecycle. When a user navigates and interacts with your app, your fragments transition through various states in their lifecycle as they are added, removed, and enter or exit the screen.
Returns The fragment's root view, or null if it has no layout.
To answer your original question, here is the order of Lifecycle callbacks
12-09 16:38:41.800 10227-10227/org.Test I/Fragment: ## OnStart()
12-09 16:38:41.820 10227-10227/org.Test I/Fragment: ## OnActivityResult()
12-09 16:38:41.821 10227-10227/org.Test I/Fragment: ## OnResume()
This is not an area I've been tinkering in or an issue that I've had, but if your variable is not visible for whatever reason... Have you tried using a different type of way to reference the value?
My suggestion would be to try using a SharedPreferences variable and saving the value there in the Editor and pulling it back out. This may not be the best solution but may be a work around for the moment.
I had the similar error message from logcat of, which is how I stumbled across your post.
"01-27 11:13:42.899: W/PhoneWindow(1591): Previously focused view reported id 16908862 during save, but can't be found during restore."
The way I was able to fix my issue was my "Blank Constructor" was not re-instansiateing my fragment. In the fragment I only have 1 variable being an 'ID' which is passed back to my activity when the user select an item with their selection. I simply re-instaniated my fragment by calling my normal constructor with the values passed in.
eg.
public UIDialogFragmentVolume() {
this(ID);
}
public UIDialogFragmentVolume(int typeID) {
ID = typeID;
}
I hope this helps you to determine and fix your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With