Android 按下注销按钮后,如何在登录活动中转发我的应用程序?
我正在开发我想知道的android应用程序 如何在从另一个活动中按注销按钮后在登录活动中转发我的应用程序?使用意向服务 以下是登录的最佳示例:Android 按下注销按钮后,如何在登录活动中转发我的应用程序?,android,android-activity,Android,Android Activity,我正在开发我想知道的android应用程序 如何在从另一个活动中按注销按钮后在登录活动中转发我的应用程序?使用意向服务 以下是登录的最佳示例: 通过以下方式调用您的登录活动 startActivity(new Intent(this, Login.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 您可以使用以下代码清除应用程序数据 /** * Call this method to delete any ca
通过以下方式调用您的登录活动
startActivity(new Intent(this, Login.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
您可以使用以下代码清除应用程序数据
/**
* Call this method to delete any cache created by app
* @param context context for your application
*/
public static void clearApplicationData(Context context) {
File cache = context.getCacheDir();
File appDir = new File(cache.getParent());
if (appDir.exists()) {
String[] children = appDir.list();
for (String s : children) {
File f = new File(appDir, s);
if(deleteDir(f))
Log.i(TAG, String.format("**************** DELETED -> (%s) *******************", f.getAbsolutePath()));
}
}
}
private static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
/**
*调用此方法删除应用程序创建的任何缓存
*@param应用程序的上下文
*/
公共静态无效clearApplicationData(上下文){
文件缓存=context.getCacheDir();
File appDir=新文件(cache.getParent());
if(appDir.exists()){
String[]children=appDir.list();
for(字符串s:子项){
文件f=新文件(appDir,s);
if(deleteDir(f))
Log.i(TAG,String.format(“*******************已删除->(%s)********************”,f.getAbsolutePath());
}
}
}
私有静态布尔deleteDir(文件目录){
if(dir!=null&&dir.isDirectory()){
String[]children=dir.list();
for(int i=0;i
为了您的关注,尝试一下这个
Intent intent = new Intent(CurrentClass.this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
例如:假设您有一个名为“后退”的后退按钮
finish()您以前的活动并运行LoginActivity通过Intent调用您的登录活动..simple.将Intent传递给另一个活动
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(CurrentClass.this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
System.exit(0);