-1

Hi guys i try to implement a back button in android studio that will bring me back to my previous activity.I manage to display the button on my app but when i press the button it just don't function .There is no error in my program.

 package com.example.window8.myfriend;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class design extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_design);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setLogo(R.drawable.images);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

}
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_image, menu);

    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();


    //noinspection SimplifiableIfStatement
    if (id == R.id.home) {

        Intent intent = new Intent(getApplicationContext(),Systemtime.class);
        startActivity(intent);

        return true;


    }

    return super.onOptionsItemSelected(item);
}

}

  • 1
    There might be any reason, try to put a log in onOptionsItemSelected and if (id == R.id.home) { } , find out where the problem is. – Remees M Syde Oct 05 '15 at 06:43

1 Answers1

-1

Back button should be android.R.id.home & below line will be used to return to parent activity.

NavUtils.navigateUpFromSameTask(this);
RyanB
  • 1,287
  • 1
  • 9
  • 28
  • @Firefog ok, OP was confirmed. Would you mind to remove your "wrong" down vote? – RyanB Oct 05 '15 at 06:38
  • @Firefog dude, I edited it to add another choice for OP to get back to parent activity instead of using startActivity. The problem still there by using wrong home button's id. Did you read OP comment yet? – RyanB Oct 05 '15 at 06:48
  • Ok I will up it when stack allow me to do this – Firefog Oct 05 '15 at 06:49
  • Could you please help me on [QUESTION](http://stackoverflow.com/questions/32937039/upgrading-db-when-using-existing-database-with-android-app) – Firefog Oct 05 '15 at 06:50