Android Back Action Button Result In App Crash
Solution 1:
The button on the top left corner is not the "Back" button, it would be the "up" button, and it's just a button in the action bar, onBackPressed refers to the hardware back button being pressed. Navigation with back and up is not necessarily the same ("back" means go to where I was before, whereas "up" means go to the upper level in the app hierarchy). Take a look at http://developer.android.com/design/patterns/navigation.html for more information.
(Also, try to avoid a splash screen, they are highly discouraged in android design patterns)
Edit: I forgot to mention how to actually handle the "up" button. You do that on your activity's onOptionsItemSelected:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
// Handle "up" button behavior here.
return true;
} else {
// handle other items here
}
// return true if you handled the button click, otherwise return false.
}
Solution 2:
You can do something like this when the back button is called
public void onBackPressed(){
// Add data to your intent
finish();
startActivity(intent);
}
And similar in your onClick method for your action bar button.
Solution 3:
I think, the problems is from passing value using intent. If the value is intended to be use by all of your activity, I think the best way is to use a sharedpreferences.
Solution 4:
If You are using API level 16 or more than , Really No need to do anythinngggg, i just Find the solution : in manifest file with every other activity Except MainActivity Add meta-data like this :
android:name="android.support.PARENT_ACTIVITY"
android:value="com.gsetia.ohama.MainActivity"/>
with in Activity like this , For Example
<activity
android:name=".ViewReports"
android:label="@string/title_activity_view_reports"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.gsetia.ohama.MainActivity"/>
</activity>
And In Last , delete public boolean onOptionsItemSelected(MenuItem item) Method. That's it.
You will find your Back Button and will work fine
Post a Comment for "Android Back Action Button Result In App Crash"