`

退出应用

 
阅读更多
如果处在安全模式,桌面没有你测试的应用图标或小米android 4.1.1系统getLaunchIntentForPackage为空时,可以采用setComponent退出到登录界面

@Override
public void onQuit() {
final CustomAlertDialog.Builder builder = new CustomAlertDialog.Builder(
this);
builder.setMessage(R.string.quit_login_dialog_title);
builder.setPositiveButton(getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
if (getApplicationContext() == null) {
return;
}
dialog.dismiss();
final ProgressDialog progressDialog = new ProgressDialog(
ProfileSettingActivity.this);
progressDialog.setMessage(ResourcesManager
.getString(R.string.quit_tip));
progressDialog.setCancelable(false);
UIUtil.showDialogSafe(progressDialog);
AsyncTaskUtils.executeAsyncTask(
new AsyncTask<Void, Void, Boolean>() {
protected Boolean doInBackground(
Void... params) {
UserPrefs.getInstance().setLogin(false);
UserPrefs.getInstance().setAgainSign(
true);
UserPrefs.getInstance().saveToken(null);
return true;
}

@Override
protected void onPostExecute(Boolean result) {
UIUtil.dismissDialogSafe(progressDialog);
MainActivity.resetStartingLoadingPage();
String packAgeName = getPackageName();
final Intent intent = getPackageManager().getLaunchIntentForPackage(packAgeName);
if(intent != null){
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else{
Intent newIntent = new Intent(Intent.ACTION_MAIN); 
newIntent.setComponent(new ComponentName(packAgeName,"com.android.xxx.activity.MainActivity")); 
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(newIntent); 
}
finish();
}
}, Priority.HIGH);
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel),
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.build().show();
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics