我有一個應用程序,從一個啓動畫面開始,然後導航到其他活動。如果我在特定活動中按下主頁按鈕,應用程序會最小化。同樣,如果我點擊應用程序圖標,應用程序將從閃屏開始。我想從按下主頁按鈕的活動中恢復我的應用程序。如何實現這一目標?Android應用程序保留狀態後,應用程序從最小化
package com.xyz.user.login;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
public class ResetPasswordActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.logout:
// Single menu item is selected do something
// Ex: launching new activity/screen or show alert message
PopIt("Are you sure you want to exit?");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void PopIt(String string) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(string)
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(
getApplicationContext(),
SignInActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reset_password);
ImageButton imgRPass=(ImageButton)findViewById(R.id.imgChangePass);
imgRPass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(ResetPasswordActivity.this,ResetPasswordMessageActivity.class);
startActivity(intent);
}
});
ImageButton imgBack=(ImageButton)findViewById(R.id.imgbtnBackFromResetPass);
imgBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
}
沒有完成()在任何活動的任何方法...... PLZ建議出路 – ParijatDev
...我這裏用的是,在應用深層提出了一個常見問題屏幕關閉菜單中的活動的應用程序,它最大限度地減少並恢復到相同的看法,沒有任何問題。你可以編輯你的問題來發布你最小化後的最小活動代碼嗎? – emrys57
done,plz chk ... – ParijatDev