如果帐户已登录但未注销,如何在启动画面后立即打开信息中心?
以下是我的启动画面代码:
public class ActSplashScreen extends AppCompatActivity {
ProgressBar progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_splash_screen);
progress=(ProgressBar)findViewById(R.id.progress) ;
Handler handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
progress.setVisibility(View.GONE);
Intent obj=new Intent(ActSplashScreen.this,CustomerLoginAct.class);
startActivity(obj);
}
},5000);
}
}
答案 0 :(得分:1)
if (mCurrentUser != null) {
// if the current user has valid serrion, then go to Around Me Activity
Intent mainIntent = new Intent(DispatchActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
} else {
// if there is no valid user session, go to Login Activity
Intent mainIntent = new Intent(DispatchActivity.this, LoginActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
}
}
单击登录按钮并在启动画面处理程序上尝试上面的代码,在共享首选项中保存登录用户的用户ID。这将检查用户ID是否存在。
答案 1 :(得分:0)
使用 SharedPreferences 来处理登录状态。像那样
创建一个单独的MySharedPref类来存储登录状态
public class MySharedPref {
SharedPreferences sharepreferences;
public static MySharedPref instance = null;
public static MySharedPref getInstance()
{
if (instance == null) {
synchronized (MySharedPref .class) {
instance = new MySharedPref();
}
}
return instance;
}
public void saveISLogged_IN(Context context, Boolean isLoggedin) {
sharepreferences = PreferenceManager
.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharepreferences.edit();
editor.putBoolean("IS_LOGIN", isLoggedin);
editor.commit();
}
public boolean getISLogged_IN(Context context) {
sharepreferences = PreferenceManager
.getDefaultSharedPreferences(context);
return sharepreferences.getBoolean("IS_LOGIN", false);
}
}
在Splash Activity中
MySharedPref mySharedPref = MySharedPref.getInstance();
Handler handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
progress.setVisibility(View.GONE);
if (!mySharedPref.getISLogged_IN(SplashActivity.this)) {
Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
startActivity(intent);
} else {
//Dashboard Activity
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
finish();
}
},5000);
请记住,当您成功登录时,您必须更改登录类。
MySharedPref.getInstance().saveISLogged_IN(Context context, true);
然后退出
MySharedPref.getInstance().saveISLogged_IN(Context context, false);
希望这会对你有所帮助。
答案 2 :(得分:-1)
按照我的理解你可以做到这一点
unsigned char array_a[4] = {0x00,0x00,0x08,0x4D};
unsigned char val[4];
float test;