Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Pouya Amirahmadi
9,167 PointsMainActivity gets killed and URI gets null, My solution
Hi guys I hope you are in "Self-Destructing app" section. As I was testing , I just noticed that on my Samsung Galaxy Note 3 device, whenever Camera gets started from MainActivity , MainACtivity gets completly destroyed so the mMediaUril would be null. here is the solution (using instance to save your data during Activity destroy/recreation).
public static final String KEY_URI_INSTANCE = "keyUriInstance";
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mMediaUri != null)
outState.putString(KEY_URI_INSTANCE, mMediaUri.toString());
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState.containsKey(KEY_URI_INSTANCE))
mMediaUri = Uri.parse(savedInstanceState.getString(KEY_URI_INSTANCE));
}
You can search in android developer to find out how onSaveInstanceState and onRestoreInstanceState works Have fun guys ;)