In SIGNIN Activity Upon clicking Sign In button data is retrieved from database in a separate background class (extending asynctask). onPostExecute I start "Navigation Drawer Activity" and send that data using intent to Navigation Drawer Activity. In "DrawerActivity" I am receiving that data and display it in a textView. I used sharedPreferences so that after successful login SIGNIN activity does not open again, so when I launch the activity second time textView has null value because no extras were passed. How to resolve this and store the value of textView permanently.
Background Class
@Override
protected void onPostExecute(final String result) {
final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(ctx);
builder.setMessage("Login Successfull");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (!result.contains("FALSE")) {
Intent i = new Intent(ctx, DrawerActivity.class);
Bundle b = new Bundle();
b.putString("name", namejsn);
b.putString("email", emailjsn);
i.putExtra("Login", b);
((Activity) ctx).finish();
ctx.startActivity(i);
}
DrawerActivity
public class DrawerActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
static String email;
static String firstName;
static String lastname;
static String profile;
ImageView imageViewHeader;
private int PICK_IMAGE_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
SharedPreferences sharedPreferences = getSharedPreferences("MyLogin.txt", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("FirstLogin", true);
editor.commit();
Intent i = getIntent();
if (i.hasExtra("Login")) {
Bundle b = i.getBundleExtra("Login");
firstName = b.getString("name");
email = b.getString("email");
Log.d("DrawerActivityLogin", email + firstName);
}
TextView tv1 = (TextView) v.findViewById(R.id.txtheader)
TextView tv2 = (TextView) v.findViewById(R.id.txtheadr2);
tv1.setText(firstName)
tv2.setText(email);