UserInfoActivity用户图像修改和退出登录

 2023-09-05 阅读 253 评论 0

摘要:@OnClick(R.id.btn_user_logout) public void logout(View view){//"退出登录"button的回调方法//1.将保存在sp中的数据清除SharedPreferences sp = this.getSharedPreferences("user_info", Context.MODE_PRIVATE);sp.edit().clear().commit();//清
@OnClick(R.id.btn_user_logout)
public void logout(View view){//"退出登录"button的回调方法//1.将保存在sp中的数据清除SharedPreferences sp = this.getSharedPreferences("user_info", Context.MODE_PRIVATE);sp.edit().clear().commit();//清除数据操作必须提交;提交以后,文件仍存在,只是文件中的数据被清除了//2.将本地保存的图片的file删除File filesDir;if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){//判断sd卡是否挂载//路径1:storage/sdcard/Android/data/包名/filesfilesDir = this.getExternalFilesDir("");}else{//手机内部存储//路径:data/data/包名/filesfilesDir = this.getFilesDir();}File file = new File(filesDir,"icon.png");if(file.exists()){file.delete();//删除存储中的文件}//3.销毁所有的activitythis.removeAll();//4.重新进入首页面this.goToActivity(MainActivity.class,null);
}

用户退出:

1.销毁当前activity

@OnClick(R.id.iv_top_back)
//返回按钮的退出操作
@OnClick(R.id.iv_top_back)
public void back(View view) {ActivityManager.getInstance().removeCurrent();
}

2.重写MeFragment的onResume()

/*** 当当前的Fragment显示时,考虑是否需要从本地读取用户头像*/
@Override
public void onResume() {super.onResume();Log.e("TAG", "onResume");readImage();
}private boolean readImage() {File filesDir;//判断sd卡是否处于挂载状态if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){filesDir = this.getActivity().getExternalFilesDir(null);//sdcard/Android/data/应用包名/file/...jpg}else{filesDir = this.getActivity().getFilesDir();}File file = new File(filesDir,"icon.png");if (file.exists()) {//如果存在//存储--->内存Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());ivMeIcon.setImageBitmap(bitmap);return true;}return false;
}

  

  

 

转载于:https://www.cnblogs.com/ganchuanpu/p/6680266.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/753.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息