//显示身份界面框
private void showIdentity() {
try {
DialogListAdapter adapter = new DialogListAdapter(MainActivity.this, identityNameList);
//dialog参数设置
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); //先得到构造器
builder.setTitle("点击进行身份切换"); //设置标题
//builder.setMessage("是否确认退出?"); //设置内容
builder.setIcon(R.mipmap.ic_launcher);//设置图标,图片id即可
//设置列表显示,注意设置了列表显示就不要设置builder.setMessage()了,否则列表不起作用。
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String uid = identityToporgidList.get(which);
// Toast.makeText(MainActivity.this, identityToporgidList.get(which), Toast.LENGTH_SHORT).show();
//1. 方法一 利用PackageManager类,该方法无效
// Intent i = getBaseContext().getPackageManager()
// .getLaunchIntentForPackage(getBaseContext().getPackageName());
// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// i.putExtra(Const.IntentCode_Toporgid,toporgid);
// startActivity(i);
//2. 方法二 利用PendingIntent,对程序进行重启
// Intent mStartActivity = new Intent(MainActivity.this, LoginActivity.class);
// int mPendingIntentId = 123456;
// mStartActivity.putExtra(Const.IntentCode_Toporgid,toporgid);
// Log.e("topid",toporgid );
// PendingIntent mPendingIntent = PendingIntent.getActivity(MainActivity.this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
// AlarmManager mgr = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE);
// mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
// System.exit(0);
User olduser = AppContext.getInstance().getLoginUser();
User user = new User();
user.setUsername(AppContext.getInstance().getLoginUser().getUsername());
user.setPwd(AppContext.getInstance().getLoginUser().getPwd());
user.setID(uid);
user.setName(AppContext.getInstance().getLoginUser().getName());
user.setSystemName(AppContext.getInstance().getLoginUser().getSystemName());
user.setToporgid(AppContext.getInstance().getLoginUser().getToporgid());
user.setProjectid(AppContext.getInstance().getLoginUser().getProjectid());//加入项目ID
user.setDatafilter(AppContext.getInstance().getLoginUser().getDatafilter());//加入数据权限
AppContext.getInstance().saveUserInfo(user);
AppContext.getInstance().updateUserInfo(user);
String id = AppContext.getInstance().getLoginUser().getID();
String title = identityMap.get(id);
menu.getItem(0).setTitle(title);
dialog.dismiss();
private void showIdentity() {
try {
DialogListAdapter adapter = new DialogListAdapter(MainActivity.this, identityNameList);
//dialog参数设置
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); //先得到构造器
builder.setTitle("点击进行身份切换"); //设置标题
//builder.setMessage("是否确认退出?"); //设置内容
builder.setIcon(R.mipmap.ic_launcher);//设置图标,图片id即可
//设置列表显示,注意设置了列表显示就不要设置builder.setMessage()了,否则列表不起作用。
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String uid = identityToporgidList.get(which);
// Toast.makeText(MainActivity.this, identityToporgidList.get(which), Toast.LENGTH_SHORT).show();
//1. 方法一 利用PackageManager类,该方法无效
// Intent i = getBaseContext().getPackageManager()
// .getLaunchIntentForPackage(getBaseContext().getPackageName());
// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// i.putExtra(Const.IntentCode_Toporgid,toporgid);
// startActivity(i);
//2. 方法二 利用PendingIntent,对程序进行重启
// Intent mStartActivity = new Intent(MainActivity.this, LoginActivity.class);
// int mPendingIntentId = 123456;
// mStartActivity.putExtra(Const.IntentCode_Toporgid,toporgid);
// Log.e("topid",toporgid );
// PendingIntent mPendingIntent = PendingIntent.getActivity(MainActivity.this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
// AlarmManager mgr = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE);
// mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
// System.exit(0);
User olduser = AppContext.getInstance().getLoginUser();
User user = new User();
user.setUsername(AppContext.getInstance().getLoginUser().getUsername());
user.setPwd(AppContext.getInstance().getLoginUser().getPwd());
user.setID(uid);
user.setName(AppContext.getInstance().getLoginUser().getName());
user.setSystemName(AppContext.getInstance().getLoginUser().getSystemName());
user.setToporgid(AppContext.getInstance().getLoginUser().getToporgid());
user.setProjectid(AppContext.getInstance().getLoginUser().getProjectid());//加入项目ID
user.setDatafilter(AppContext.getInstance().getLoginUser().getDatafilter());//加入数据权限
AppContext.getInstance().saveUserInfo(user);
AppContext.getInstance().updateUserInfo(user);
String id = AppContext.getInstance().getLoginUser().getID();
String title = identityMap.get(id);
menu.getItem(0).setTitle(title);
dialog.dismiss();