Activity not running in background in android
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);
}
}
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
Check your manifest file. Your activity has probably noHistory=true
attribute. If not then check flags where activity is starting.
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
精彩评论