한 액티비티에서 다른 액티비티로 이동하면 인 텐트가 아닌 백 스택에서 탐색하는 경우 편집 된 필드를 사용할 수 있습니다. .
예를
돌아 가기 스택 -> 당신이에 이전 활동을 호출합니다 뒤로 버튼을 눌러
의도 -> startActivity를 (새 의도 (ActivityA.this, ActivityB.class));
당신이 활동을 변경하기위한 의도를 사용하는 경우 그렇게 편집 된 필드는 사용할 수 없습니다 활동 ... 지금까지 당신이 사용자가 당신이 공유 사용할 필요가 돌아온 후 필드를 저장하려는 경우
을 다시합니다 환경 설정 ...
Refer the official documentation
난 당신에게 공유 환경 설정 값을 저장하고 그것에서 검색하는 샘플을 제공 할 수 있습니다.
public class CommonUtil {
public static void setUserName(String userName,Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("user_name",userName);
editor.apply();
}
public static String getUserName(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getString("user_name",null);
}}
는 사용자가 i가 텍스트 필드
업데이트 CommonUtil 방법
에서 값을 업데이트합니다 떠나려고하면 값이
CommonUtil.setUserName("user",getApplicationContext());
CommonUtil.getUserName(getApplicationContext());
활동
을 형성 설정하려면 ..
키가 될 것입니다 어디에 어떤 값이 텍스트 필드에서 이동합니다 사용자 이름, 암호
public static void setValues(String key,String value, Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(key);
editor.putString(key,value);
editor.apply();
}
public static String getValues(String key,Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getString(key,null);
}
당신은 또한 가능하다 루핑 선호하는 경우
에 대한
최종 솔루션 당신의 문제 ..
final EditText username,surname,middlename,dob,email,password;
Button get,save;
final String[] keyset = new String[]{"username","surname","middlename","dob","email","password"};
username = (EditText) findViewById(R.id.username);
surname = (EditText) findViewById(R.id.surname);
middlename = (EditText) findViewById(R.id.middlename);
dob = (EditText) findViewById(R.id.dob);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
final EditText[] editTexts = {username,surname,middlename,dob,email,password};
get = (Button) findViewById(R.id.get);
save = (Button) findViewById(R.id.save);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i =0 ; i<6 ;i++){
CommonUtil.setValues(keyset[i],editTexts[i].getText().toString(),getApplicationContext());
Log.d("got",editTexts[i].getText().toString());
}
}
});
get.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i =0 ; i<6 ;i++){
CommonUtil.getValues(keyset[i],getApplicationContext());
Log.d("got",CommonUtil.getValues(keyset[i],getApplicationContext()));
}
}
});
감사합니다. 내 상황은 다음과 같습니다. 입력 한 내용을 입력했습니다. 활동 A에서 lds를 선택하고 NEXT 버튼을 사용하여 활동 B로 이동하십시오. 활동 B의 입력 필드를 채 웠습니다. 활동 B는 이전 활동 A로 돌아 가기위한 단추가 있습니다. 작업 A에서 NEXT 버튼을 다시 클릭하면 작업 B가 다시 시작됩니다. 나는 이것을 원하지 않는다. 나는 입력 된 B 입력 필드를 원한다. A 액티비티에서 B 액티비티를 다시 시작할 수있는 방법이있다. – user8140661