3
로그인, 로그 아웃 기능이있는 Android 앱이 하나 있습니다. 로그인 양식에는 사용자 이름과 암호 및 로그인 버튼이 있습니다. 사용자가 "내 정보 저장"확인란을 선택하면 사용자 이름과 암호를 저장하려고합니다.로그인 정보 (환경 설정) android
내 project.java 파일은 다음과 같습니다 :
public class project extends Activity {
private static final int IO_BUFFER_SIZE = 4 * 1024;
/** Called when the activity is first created. */
public int user_id,current_user_id;
public String access_token,username,current_username;
public boolean user_logged_in=false;
public ProgressDialog progdialog;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
progdialog = new ProgressDialog(this);
progdialog.setMessage("loading...");
initLogin();
}
public void initLogin(){
setContentView(R.layout.login);
Button button = (Button) findViewById(R.id.login_login);
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
login();
}
});
}
public void login(){
try{
String login_username=(((EditText) findViewById(R.id.login_username)).getText()).toString();
String login_password=(((EditText) findViewById(R.id.login_password)).getText()).toString();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username",login_username));
nameValuePairs.add(new BasicNameValuePair("password",login_password));
String content=postUrlContent(api_url+"landing/authenticate",nameValuePairs);
JSONObject jObject = new JSONObject(content);
JSONObject respObject = jObject.getJSONObject("response");
Boolean success=respObject.getBoolean("success");
String message=respObject.getString("message");
Boolean logged_in=respObject.getBoolean("logged_in");
if(logged_in){
user_id=respObject.getInt("user_id");
access_token=respObject.getString("access_token");
username=respObject.getString("username");
current_username=username;
current_user_id=user_id;
user_logged_in=true;
//initFeeds(username);
test(0);
}else{
createDialog("Error",message);
}
}catch(Exception e){
}
}
내가 같은 자바 파일 자체에이 위의 코드를 사용할 수있는 다음의 환경 설정은 당신의에서 onCreate 방법과 같은 정보에 액세스하려면 다음의 환경 설정
에 설정된 키를 사용하여 언제든지 액세스 할 수 있습니다 ? – user768990
가능합니다. 동일한 SharedPreferences는 앱의 모든 활동에 액세스 할 수 있습니다. –
정말 고마워요, 지금 확인해 보겠습니다. – user768990