gpt4 book ai didi

java - 无法调用共享 Preferences 类的函数(构造函数)来维护 session

转载 作者:太空宇宙 更新时间:2023-11-04 11:00:28 25 4
gpt4 key购买 nike

我创建了一个用于存储 session 的类,因此如果用户没有注销,我可以绕过登录屏幕,但我不知道为什么我无法访问该类的函数(构造函数)。

package pk.com.edu.farrukhabbas.hcs.Combined;
import java.util.HashMap;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import pk.com.edu.farrukhabbas.hcs.Doctor.DoctorSignInActivity;

class SessionManager {
// Shared Preferences
SharedPreferences pref;

// Editor for Shared preferences
Editor editor;

// Context
Context _context;

// Shared pref mode
int PRIVATE_MODE = 0;

// Sharedpref file name
private static final String PREF_NAME = "Farrukh Abbas" , IS_LOGIN = "" , KEY_NAME = "", KEY_EMAIL = "", KEY_USERDESIG = "", KEY_ID = "", KEY_MOBILE = "", KEY_CNIC = "",
KEY_DOB = "", KEY_GENDER = "", KEY_PASSWORD = "", KEY_LAT = "", KEY_LONG = "";


// Constructor
public SessionManager(Context context) {
this._context = context;

pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);

editor = pref.edit();
}
public void session()
{

}

public void createPatientLoginSession(String USERDESIG, String ID, String NAME, String MOBILE, String CNIC, String DOB, String EMAIL, String GENDER, String PASSWORD)
{
// Storing login value as TRUE
editor.putBoolean(IS_LOGIN, true);

editor.putString(KEY_NAME, NAME);

editor.putString(KEY_USERDESIG, USERDESIG);

editor.putString(KEY_CNIC, CNIC);

editor.putString(KEY_ID, ID);

editor.putString(KEY_DOB, DOB);

editor.putString(KEY_MOBILE, MOBILE);

editor.putString(KEY_GENDER, GENDER);

editor.putString(KEY_EMAIL, EMAIL);


editor.putString(KEY_PASSWORD, PASSWORD);



// commit changes
editor.commit();
}


/**
* Quick check for login
* **/
// Get Login State
public boolean isLoggedIn(){
return pref.getBoolean(IS_LOGIN, false);
}


public void checkLogin(){
// Check login status
if(!this.isLoggedIn()){
// user is not logged in redirect him to Login Activity
if(KEY_USERDESIG.equals("Doctor")) {
Intent i = new Intent(_context, DoctorSignInActivity.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
_context.startActivity(i);
}
else
{
Intent i = new Intent(_context, SignInActivity.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
_context.startActivity(i);


}
}

}

/**
* Clear session details
* */
public void logoutUser(){
// Clearing all data from Shared Preferences

String userDeignation = KEY_USERDESIG;

editor.clear();
editor.commit();

if(userDeignation.equals("Doctor")) {
Intent i = new Intent(_context, DoctorSignInActivity.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
_context.startActivity(i);
}
else
{
Intent i = new Intent(_context, SignInActivity.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
_context.startActivity(i);

}


}

}

这是我的主调用中的代码,我在其中创建其对象并调用其构造函数

SessionManager session;
session = new SessionManager((zzw) getApplicationContext());
session.createPatientLoginSession(userDesignation, user_Id , user_Name
,user_Mobile ,user_Cnic, user_Dob , user_Email ,user_Gender,
user_Password);

enter image description here

最佳答案

类SessionManager是类中的一个Bilt编译器正在寻找该函数

createPatientLoginSession()

在该内置类中,因为它具有高优先级将类“SessionManager”的名称更改为任何其他名称即可解决问题

关于java - 无法调用共享 Preferences 类的函数(构造函数)来维护 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46961815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com