android - Error when usig back button from Action Bar -


I have an activity called A, which takes extra on startup. The problem is that when the back button If pressed, then use B setDisplayHomeAsUpEnabled (true); I get an error setDisplayHomeAsUpEnabled (true);

How do I send extra to B to A while using the back button? Activity A starts this way, the main activity says that

  creates a protected void (InstanceState saved from bundle) {// Tudo auto-generated method stub super. Contents (Saved Instantstate); SetContentView (R.layout.activity_subscreen); Bundle Extras = Milentant (). GetExtras (); TitleTask = extras.getString (DatabaseHelper.COLUMN_TITLE); Titid = extras.getLong (DataShelper.COLUMN_ROWID); ActionBar = getSupportActionBar (); ActionBar.setTitle (titleTask); ActionBar.setDisplayHomeAsUpEnabled (true); }   

The log error is as follows:

  04-26 12: 39: 54.355: Back button pressed from E / AndromedaTime (15573): Java KlangkRuntimeException: activity unable to start ComponentInfo {com.group.RedPanda.FinalProject / com.group.RedPanda.FinalProject.SubScreen}: java.lang.NullPointerException 04-26 December: 39: 54.355: e / AndroidRuntime ( 15 573): 04-26 on android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2663) 12: 39: 54.355: e / AndroidRuntime (15,573): android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2679) 04 -26 12: 39: 54.355: E / AndroidRuntime (15,573): 39 :: 54.355: android.app.ActivityThread.access $ 2300 (ActivityThread.java:125) December 04-26 E / AndroidRuntime (15,573): android App Su. ActivityThread $ H.handleMessage (ActivityThread.java:2033) 04-26 12: 39: 54.355: E / AndroidRuntime (15,573): android.os.Handler.dispatchMessage (Handler.java:99) on 04-26 12:39: 54.355: E / Android Rendime (15573): Android.OS Looper Loop (Looper.java:123) 04-26 12: 39: 54.355: E / Endrumi dRuntime (15,573): at android.app.ActivityThread.main (ActivityThread.java:4627) 04-26 December: 39: 54.355: E / AndroidRuntime (15,573): java.lang.reflect.Method.invokeNative at (native resident method) 04-26 December: 39: 54.355: E / AndroidRuntime (15,573): at java.lang.reflect.Method.invoke (Method. java: 521) 04-26 December: 39: 54.355: e / AndroidRuntime (15,573): in com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:860) 04-26 December: 39: 54.355: e / AndroidRuntime (15,573): to com.android.internal.os.ZygoteInit.main (ZygoteInit Java: 618) 04-26 December: 39: 54.355: e / AndroidRuntime (15,573): to dalvik.system.NativeStart.main ( Native Method) 04-26 Dec. 39: 54.355: E / AndroidRuntime (15,573): A Shelter by: java.lang.NullPointerException 04-26 December: 39: 54.355: 04-26 December E / AndroidRuntime (15,573): com.group.RedPanda.FinalProject.SubScreen.onCreate (SubScreen.java:29): 39: 54.355: e / AndroidRuntime (15,573): android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1047) on 04-26 December: 39: 54.355: e / AndroidRuntime (15,573): android.app.Acti on vityThread.performLaunchActivity ( ActivityThread.javamore627)    

Try this..what do you want to do true There is something on the lines of this:

  @Override Public Boolean onOptionsItemSelected (MenuItem MENUITEM) {Switch (menuItem.getItemId ()) {Case android.R.id.home: Intent Maintent = new Intent (this, Homaktivtikclas); HomeIntent.addFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP); StartActivity (homeIntent); } Return (super.onOptionsItemSelected (menuItem)); }   

Instead of going back to you through the stack, you will move to the original activity. I have also added Intent.Flag to clear the back stack, when going to home activity and when your users are using the 'up' button, they can be useful in preventing the mess in the back

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -