public class Loginscreen extends Activity {
private EditText phonenumber,password;
private Button signin,joinus,supportus;
private TextView forgot_password;
String mobilenumber;
String passwordtxt;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginscreen);
phonenumber = (EditText) findViewById(R.id.edt_username);
password = (EditText) findViewById(R.id.edt_password);
signin = (Button) findViewById(R.id.bt_signin);
joinus = (Button) findViewById(R.id.bt_joinus);
supportus = (Button) findViewById(R.id.bt_supportus);
forgot_password = (TextView) findViewById(R.id.txt_remember_pawd);
final String user = phonenumber.getText().toString();
final String pass = password.getText().toString();
signin.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
//final Intent intent;
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
final String pasword = pref.getString("pwd", null);
final String phnenumber = pref.getString("mobilenumber", null);
if (pass == pasword && user == phnenumber && !pass.isEmpty()){
Toast.makeText(Loginscreen.this, "correct ", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Loginscreen.this, "Incorrect Mobile number or password", Toast.LENGTH_SHORT).show();
}
}
});
@Override
public void onPostExecute(String result) {
JSONObject jsonobject = null;
try {
jsonobject = new JSONObject(result);
JSONObject object = jsonobject.getJSONObject("data");
String id = object.getString("_id");
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
pref.getString("key_name1",null);
//final String encoded = pref.getString("key_name1",null);
String password = getIntent().getStringExtra("_password");
String mobilen = getIntent().getStringExtra("mobile");
SharedPreferences.Editor editor = pref.edit();
editor.putString("pwd",password);
editor.putString("mobilenumber",mobilen);
editor.putString("user_id",id);
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
Yukarıdaki kod başka bir etkinlikle mevcuttur .. başka bir sayfaya tercihini paylaştı kullandık. .Her ikisi de eşit olan değerleri karşılaştırmak için LoginScreen'de bu paylaşılan tercih değerini kullanabilir miyim?
Bundle ve putExtra'yu Niyet'e kullanabilir veya 'Static' Variable'ı kullanabilirsiniz. – Aizen