我有一個名爲「A」的應用程序,其中包含一個名爲「CloginSession」的類,我在「B」應用程序中有一個名爲「B」的應用程序,我想讓CLoginSession的對象檢查用戶是否登錄或不能。我這樣做,如何在android中的其他應用程序中調用其他應用程序活動?
這裏是CLoginSession代碼: -
public class CLoginSessionManagement {
// User name (make variable public to access from outside)
public static final String s_szKEY_MOBILE = "agentcode";
// Email address (make variable public to access from outside)
public static final String s_szKEY_PASSWORD = "pin";
// Sharedpref file name
private static final String s_szPREF_NAME = "LoginData";
// All Shared Preferences Keys
private static final String s_szIS_LOGIN = "IsLoggedIn";
private final SharedPreferences m_LOGIN_PREF;
private final Editor m_EDITOR;
private final Context m_CONTEXT;
// Constructor
@SuppressLint("CommitPrefEdits")
public CLoginSessionManagement(Context m_CONTEXT) {
this.m_CONTEXT = m_CONTEXT;
m_LOGIN_PREF = m_CONTEXT.getSharedPreferences(s_szPREF_NAME, Context.MODE_PRIVATE);
m_EDITOR = m_LOGIN_PREF.edit();
}
// Registeration Session Management....
public void setLoginData(String mobile, String pin) {
m_EDITOR.putBoolean(s_szIS_LOGIN, true);
m_EDITOR.putString(s_szKEY_MOBILE, mobile);
m_EDITOR.putString(s_szKEY_PASSWORD, pin);
m_EDITOR.commit();
}
/**
* checkLogin() session wil check user Login status
* If false it will redirect user to Login page
* Else won't do anything
*/
public boolean checkLogin() {
if (!isLogin()) {
Intent i = new Intent(m_CONTEXT, CMainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
m_CONTEXT.startActivity(i);
return true;
}
return false;
}
/**
* Get stored Login session data
*/
public HashMap<String, String> getLoginDetails() {
HashMap<String, String> user = new HashMap<>();
// user name
user.put(s_szKEY_MOBILE, m_LOGIN_PREF.getString(s_szKEY_MOBILE, null));
// user email id
user.put(s_szKEY_PASSWORD, m_LOGIN_PREF.getString(s_szKEY_PASSWORD, null));
// return user
return user;
}
public boolean isLogin() {
return m_LOGIN_PREF.getBoolean(s_szIS_LOGIN, false);
}
/**
* Clear session details
*/
public void logoutUser() {
// Clearing all data from Shared Preferences
m_EDITOR.clear();
m_EDITOR.commit();
@SuppressWarnings("UnusedAssignment") final AppCompatActivity activity = (AppCompatActivity) m_CONTEXT;
Intent i = new Intent(m_CONTEXT, CLoginScreen.class);
// Closing all the Activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Staring Login Activity
m_CONTEXT.startActivity(i);
((AppCompatActivity) m_CONTEXT).finish();
}
}
是應用程序是在Play商店中重定向? –
是............. – vishwas