3

Up Navigation in Android is not working. All I want it to do is go back. However everytime I click the back button it closes the app. I followed android developer. My error log doesnt even say anthing useful so I have no idea why this is happening. My first main view is a google maps activity, and my second view is a blank activity with a listview on top of it.

Here is my error log

03-14 11:20:56.261  19816-19816/com.example.anusha.app I/SELinux Function:selinux_android_load_priority , priority [2] , priority version is    VE=SEPF_SAMSUNG-SGH-I337_4.4.4_0032
03-14 11:20:56.261  19816-19816/com.example.anusha.app E/dalvikvm﹕ >>>>> Normal User
03-14 11:20:56.261  19816-19816/com.example.anusha.app E/dalvikvm﹕ >>>>> com.example.anusha.app [ userId:0 | appId:10250 ]
03-14 11:20:56.271  19816-19816/com.example.anusha.app D/dalvikvm﹕ Late-enabling CheckJNI
03-14 11:20:56.412  19816-19816/com.example.anusha.app I/x﹕ Making Creator dynamically
03-14 11:20:56.472  19816-19816/com.example.anusha.app I/Google Maps Android API﹕ Google Play services client version: 6587000
03-14 11:20:56.472  19816-19816/com.example.anusha.app I/Google Maps Android API﹕ Google Play services package version: 6776038
03-14 11:20:57.453  19816-19816/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4226K, 23% free 20774K/26904K, paused 41ms, total 42ms
03-14 11:20:57.543  19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.ew.c
03-14 11:20:57.543  19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 441: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
03-14 11:20:57.543  19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000f
03-14 11:20:57.613  19816-19957/com.example.anusha.app W/ActivityThread﹕ ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
03-14 11:20:57.673  19816-19816/com.example.anusha.app D/AbsListView﹕ Get MotionRecognitionManager
03-14 11:20:57.823  19816-19816/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1176K, 20% free 21645K/26904K, paused 53ms, total 53ms
03-14 11:20:57.983  19816-19816/com.example.anusha.app D/Activity﹕ #1 setTransGradationModeColor false
03-14 11:20:58.023  19816-19816/com.example.anusha.app I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build:  (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
03-14 11:20:58.143  19816-19816/com.example.anusha.app D/OpenGLRenderer﹕ Enabling debug mode 0
03-14 11:20:58.353  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1659K, 19% free 22025K/26904K, paused 72ms, total 73ms
03-14 11:20:58.614  19816-19972/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1364K, 18% free 22317K/26904K, paused 48ms, total 48ms
03-14 11:20:58.744  19816-19972/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 91K, 17% free 22589K/26904K, paused 45ms, total 45ms
03-14 11:20:58.804  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 367K, 16% free 23090K/27344K, paused 35ms, total 35ms
03-14 11:20:59.154  19816-19972/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 11145K, 33% free 27756K/41368K, paused 47ms, total 47ms
03-14 11:20:59.234  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4822K, 44% free 23455K/41368K, paused 34ms, total 34ms
03-14 11:20:59.244  19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.763MB for 4194320-byte allocation
03-14 11:20:59.374  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4367K, 44% free 23465K/41368K, paused 35ms, total 35ms
03-14 11:20:59.374  19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.773MB for 4194320-byte allocation
03-14 11:20:59.495  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4234K, 44% free 23466K/41368K, paused 46ms, total 46ms
03-14 11:20:59.495  19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.774MB for 4194320-byte allocation
03-14 11:20:59.595  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4234K, 44% free 23466K/41368K, paused 36ms, total 36ms
03-14 11:20:59.595  19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.774MB for 4194320-byte allocation
03-14 11:20:59.705  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4240K, 44% free 23458K/41368K, paused 42ms, total 42ms
03-14 11:20:59.705  19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.766MB for 4194320-byte allocation
03-14 11:20:59.805  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4233K, 44% free 23459K/41368K, paused 40ms, total 40ms
03-14 11:20:59.805  19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.767MB for 4194320-byte allocation
03-14 11:21:00.075  19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 6133K, 44% free 23465K/41368K, paused 79ms, total 79ms
03-14 11:21:12.057  19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
03-14 11:21:12.057  19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 11751: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
03-14 11:21:12.057  19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-14 11:21:12.067  19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
03-14 11:21:12.067  19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 11757: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
03-14 11:21:12.067  19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-14 11:21:12.067  19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
03-14 11:21:12.067  19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 9402: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
03-14 11:21:12.067  19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
03-14 11:21:12.067  19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
03-14 11:21:12.067  19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 537: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-14 11:21:12.067  19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-14 11:21:12.067  19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-14 11:21:12.067  19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 559: Landroid/content/res/TypedArray;.getType (I)I
 03-14 11:21:12.067  19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-14 11:21:12.107  19816-19816/com.example.anusha.app D/AbsListView﹕ Get MotionRecognitionManager
03-14 11:21:12.117  19816-19816/com.example.anusha.app D/Activity﹕ #1 setTransGradationModeColor false
03-14 11:21:12.637  19816-19816/com.example.anusha.app D/AbsListView﹕ onDetachedFromWindow
03-14 11:21:14.019  19816-19816/com.example.anusha.app V/recreate activity﹕ shouldUpRecreateTask = false
03-14 11:21:14.699  19816-19816/com.example.anusha.app D/AbsListView﹕ onDetachedFromWindow
03-14 11:23:18.887  21337-21337/com.example.anusha.app I/SELinux﹕ Function: selinux_android_load_priority , priority [2] , priority version is VE=SEPF_SAMSUNG-SGH-I337_4.4.4_0032

.

 @Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.button:
            Add();
            return true;
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is NOT part of this app's task, so create a new task
                // when navigating up, with a synthesized back stack.
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                                // Navigate up to the closest parent
                        .startActivities();
            } else {
                // This activity is part of this app's task, so simply
                // navigate up to the logical parent activity.
                upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                NavUtils.navigateUpTo(this, upIntent);
                Log.v("recreate activity", "shouldUpRecreateTask = false");

            }
            return true;
    }
    return super.onOptionsItemSelected(item);
  }

Here is my manifest

 <activity
        android:name=".SilentGeofence"
        android:label="@string/title_activity_silent_geofence"
        android:parentActivityName=".AddressList" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".AddressList" />

    </activity> 
ShahiM
  • 3,179
  • 1
  • 33
  • 58
anu
  • 703
  • 1
  • 10
  • 19
  • You just want it to recreate the back button effect? – joao2fast4u Mar 14 '15 at 18:50
  • @joao2fast4u yes. but it keeps closing the app I hav tried NavUtils.navigateUpFromSameTask(this); but that doesnt work either. – anu Mar 14 '15 at 18:53
  • Is map activity parent of list activity? – krishna Mar 14 '15 at 18:55
  • Yes my main view is a mapsactivity. Then I press a button and it goes into list activity (AddressList). I want the user to be able to go back to the MapsActivity from AddressList. @KrishnaTejaVelagapudi – anu Mar 14 '15 at 18:57
  • If its a parent activity the up button will take you to the map activity with out you doing anything as far as I know – krishna Mar 14 '15 at 19:00
  • I agree. It should take you up to the parentActvity, however every time I press the back button the app closes. It doesn't crash but it closes and i have no idea why @KrishnaTejaVelagapudi – anu Mar 14 '15 at 19:02
  • ok when you are going from map activity to list activity with an intent are you finishing the map activity like startActivity(listIntent); then finish(); – krishna Mar 14 '15 at 19:06
  • Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v ) { Intent intent = new Intent(MapsActivity.this, AddressList.class); startActivity(intent); finish(); } }); } @KrishnaTejaVelagapudi – anu Mar 14 '15 at 19:07

2 Answers2

1
    Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v ) { Intent intent = new Intent(MapsActivity.this, AddressList.class); startActivity(intent);} }); } 

remove finish and it will work

krishna
  • 609
  • 8
  • 21
  • when you say finish(); android won't save the activity in backstack – krishna Mar 14 '15 at 19:11
  • Its how finish() works. If you don't want your activity in backstack you use finsih(); after starting another activity with intent otherwise you don't say finish() – krishna Mar 14 '15 at 19:14
0

If you just want to click the Action bar home button and go back, replace your code in your case android.R.id.home: by this:

super.onBackPressed();
break;

This will recreate the back button press.

joao2fast4u
  • 6,868
  • 5
  • 28
  • 42
  • didn't work. What should you recommend I do? I've tried every solution. I think I should just quit upNavigation and make my own backbutton @joao2fast4u – anu Mar 14 '15 at 19:06