0

How to keep the button activity on background/pause or something like this when i press the physical back button . I want this activity to set on when i press again the button.(to show me what did i paint in last activity);

MainActivity :

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button buttonSave=(Button)findViewById(R.id.buttonDraw);
    buttonSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub          
            startActivity(new Intent(MainActivity.this,ButtonDraw.class));              
        }
    });    
}

ButtonDraw :

public class ButtonDraw extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(com.example.myfirstapp.R.layout.paintingfile);

      BlackPixel blackPixel;
      blackPixel = new BlackPixel(this);
      setContentView(blackPixel);
      blackPixel.requestFocus();    
    }
}
Jagadesh Seeram
  • 2,630
  • 1
  • 16
  • 29
  • 1
    Can you clarify what you're asking for? You can override `onBackPressed()` of an activity, but it's difficult to understand what you want to happen. – dm78 Nov 23 '13 at 19:07
  • Maybe you need to save you state? http://stackoverflow.com/questions/151777/saving-activity-state-in-android – dilix Nov 23 '13 at 19:09

1 Answers1

0

In your MainActivity include this method:-

@Override   


public void onBackPressed() {
  startActivity(new Intent(this,ButtonDraw.class));
  finish(); // this line depends on you whether you want to finish the MainActivity or not.
  }

The above method gives you control over the back button of android.

Naddy
  • 2,664
  • 6
  • 25
  • 38