Baalback
Baalback

Reputation: 461

what should be in added in the manifestfor The method getSupportActionBar() works?

In android dev tutorials they explained when I click the icon on the left , it will throw me the "main page" with the below code:

ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

and I knew that I need to add for the class ActionBarActivity. but still I am not able to go back to the main page maybe problem with manifest.

Display.java

@Override 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grid_main);
    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));
    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

This is the manifest:

<activity
        android:name="com.example.sqlfirst.Display"
        android:label="@string/app_name"
         android:parentActivityName="com.example.sqlfirst.Display.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.sqlfirst.Display.MainActivity" />
        </activity>

why its not going to main page? Note that my main page is : MainActivity.java

Upvotes: 3

Views: 64

Answers (1)

Jayesh Elamgodil
Jayesh Elamgodil

Reputation: 1477

As per the link http://developer.android.com/training/implementing-navigation/ancestral.html#up

setDisplayHomeAsUpEnabled(true);

adds a left-facing caret alongside the app icon and enables it as an action button such that when the user presses it, your activity receives a call to onOptionsItemSelected(). The ID for the action is android.R.id.home.

You should override onOptionsItemSelected and use NavUtils

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
    NavUtils.navigateUpFromSameTask(this);
    return true;
}
return super.onOptionsItemSelected(item);

}

More details at http://developer.android.com/training/implementing-navigation/ancestral.html#NavigateUp

Upvotes: 2

Related Questions