1

When clicking on the home button and restarting the application again, it starts from the first screen rather than staying at the screen I left.

Thanks for help.

public class WelcomeScreen extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    private Button signUp,login;
    private RelativeLayout relative;
    GlobalVariable global;

    @Override
    public void onCreate(Bundle savedInstanceState)
        {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            requestWindowFeature(Window.FEATURE_PROGRESS);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            global=(GlobalVariable)getApplicationContext();
            signUp=(Button)findViewById(R.id.signUp);
            login=(Button)findViewById(R.id.login);
            relative=(RelativeLayout)findViewById(R.id.welcome_panel);
            signUp.setOnClickListener(WelcomeScreen.this);
            login.setOnClickListener(WelcomeScreen.this);   
        }
    @Override
    public void onResume()
    {
        super.onResume();
        Toast.makeText(WelcomeScreen.this, "  onResume called", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onPause()
    {
        super.onPause();
        Toast.makeText(WelcomeScreen.this, "  onPause called", Toast.LENGTH_SHORT).show();
    }
    /*
     * Button Onclick event for signup and login button
     * 
     */
    public void onClick(View v) 
    {

            if(v==signUp)
            {
                Intent signupPanel=new Intent(WelcomeScreen.this,SignupPanel.class);
                startActivity(signupPanel);
                callNull();
            }
            else if(v==login)
            {
                //start a login screen              
                Intent loginPanel=new Intent(WelcomeScreen.this,LoginPanel.class);
                startActivity(loginPanel);
                callNull();
            }

    }

    public void callNull()
    {   
        this.finish();  
    }
    @Override
    public void onDestroy()
    {
        super.onDestroy();
        Toast.makeText(WelcomeScreen.this, " on destroy called", Toast.LENGTH_SHORT).show();
        System.gc();
        relative.setBackgroundDrawable(null);
        login.setBackgroundDrawable(null);
        signUp.setBackgroundDrawable(null);

    }
     public boolean onKeyDown(int keyCode, KeyEvent event) 
        {
              if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) 
              {
                  //  android.os.Process.killProcess(android.os.Process.myPid());


                    return true;
              }

              return super.onKeyDown(keyCode,event);
        }

}
WarrenFaith
  • 56,949
  • 25
  • 133
  • 147
Kakey
  • 3,860
  • 5
  • 28
  • 45

3 Answers3

1

Please check in your whether you have handle home key press event. If you have written your home key press wvent then i think this problem may occur.

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub

        if (keyCode == KeyEvent.KEYCODE_HOME){
            // did you write your code to launc your application here
        }
        return super.onKeyDown(keyCode, event);
    }

Thanks Deepak

Sunil Kumar Sahoo
  • 51,611
  • 53
  • 174
  • 242
1

Check your manifest file. Your activity has probably noHistory=true attribute. If not then check flags where activity is starting.

pawelzieba
  • 16,024
  • 3
  • 43
  • 72
  • which doesn't explain why the app doesn't go to into background. – WarrenFaith May 27 '11 at 10:59
  • I thought that I misunderstood the question, but after Jinda comment I'm not sure. – pawelzieba May 27 '11 at 11:31
  • @WARREN simply,when the clicking on the home button,the activity loses its state in my application.why? – Kakey May 27 '11 at 12:26
  • @Jinda You mean activity stack? – pawelzieba May 27 '11 at 12:54
  • yes.exactly this thread is explained i asked. http://stackoverflow.com/questions/2061143/android-keep-tasks-activity-stack-after-restart-from-home/2061447 – Kakey May 27 '11 at 13:05
  • 1
    @Jinda: was it so hard to tell that you actually start your app again? Your question reads like you pressed the home button but instead of going to home the application goes back to your first activity. Next time be much more descriptive in your explanation... otherwise you just waste our time! – WarrenFaith May 27 '11 at 13:09
1

I feel it is the issue of statemantiance. Just create a hashmap and store the latest view their. and write a condition which wil set the view. if there is no entry in hashmap then show first screen alse so the desired screen.

If you can get better idea for state mantainance then that wil be better Thanks Deepak

Sunil Kumar Sahoo
  • 51,611
  • 53
  • 174
  • 242