我在Android上进行了自动登录,代码如下。但我得到这个错误:
在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) 运行(RuntimeInit.java:492) I/Process:发送信号。PID:14850 SIG:9 进程 14850 终止。
这是我的欢迎活动代码:
public class welcome_activity extends AppCompatActivity {
SessionManager sessionManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
sessionManager = new SessionManager(this);
sessionManager.checkLogin();
HashMap<String, String> user = sessionManager.getUserDetail();
String mNip = user.get(sessionManager.NIP);
if (mNip.equals(mNip)) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(welcome_activity.this, DashboardActivity.class);
startActivity(intent);
finish();
}
}, 2000);
} else {
Intent intent = new Intent(welcome_activity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}
}
这是我的会话管理器:
public class SessionManager {
SharedPreferences sharedPreferences;
public SharedPreferences.Editor editor;
public Context context;
int PRIVATE_MODE = 0;
private static final String PREF_NAME = "LOGIN";
private static final String LOGIN = "IS_LOGIN";
public static final String NM_LENGKAP = "NM_LENGKAP";
public static final String NIP = "NIP";
public static final String PASSWORD = "PASSWORD";
public static final String JABATAN = "JABATAN";
public static final String OPD = "OPD";
public static final String GAMBAR = "GAMBAR";
public SessionManager(Context context) {
this.context = context;
sharedPreferences = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = sharedPreferences.edit();
}
public void createSession(String nm_lengkap, String nip, String password, String jabatan,String opd,String gambar) {
editor.putBoolean(LOGIN, true);
editor.putString(NM_LENGKAP, nm_lengkap);
editor.putString(NIP, nip);
editor.putString(PASSWORD, password);
editor.putString(JABATAN, jabatan);
editor.putString(OPD, opd);
editor.putString(GAMBAR, gambar);
editor.apply();
}
public boolean isLoggin() {
return sharedPreferences.getBoolean(LOGIN, false);
}
public void checkLogin() {
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((DashboardActivity) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((welcome_activity) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((Absen_Activity1) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((Absen_Activity2) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((UbahPwd) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((Lihat_Absen1) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((Lihat_Absen2) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((Sudah_Activity) context).finish();
}
if (!this.isLoggin()) {
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((ProfileActivity) context).finish();
}
}
public HashMap<String, String> getUserDetail() {
HashMap<String, String> user = new HashMap<>();
user.put(NM_LENGKAP, sharedPreferences.getString(NM_LENGKAP, null));
user.put(NIP, sharedPreferences.getString(NIP, null));
user.put(PASSWORD, sharedPreferences.getString(PASSWORD, null));
user.put(JABATAN, sharedPreferences.getString(JABATAN, null));
user.put(OPD, sharedPreferences.getString(OPD, null));
user.put(GAMBAR, sharedPreferences.getString(GAMBAR , null));
return user;
}
public void logout() {
editor.clear();
editor.commit();
Intent i = new Intent(context, LoginActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
有人可以告诉我发生了什么吗?