Ejemplo n.º 1
0
  /**
   * Logging out the user. Will set isLoggedIn flag to false in shared preferences Clears the user
   * data from sqlite users table
   */
  private void logoutUser() {
    session.setLogin(false);

    db.deleteUsers();

    // Launching the login activity
    Intent intent = new Intent(MainActivity.this, LoginActivity.class);
    startActivity(intent);
    finish();
  }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    txtName = (TextView) findViewById(R.id.name);
    txtEmail = (TextView) findViewById(R.id.email);
    btnLogout = (Button) findViewById(R.id.btnLogout);
    btnLinkToImage = (Button) findViewById(R.id.btnLinkToImageScreen);
    btnLinkToWeather = (Button) findViewById(R.id.btnLinkToWeatherScreen);

    // SqLite database handler
    db = new DatabaseHelper(getApplicationContext());
    // session manager
    session = new SessionManager(getApplicationContext());

    if (!session.isLoggedIn()) {
      logoutUser();
    }

    // Fetching user details from SQLite
    HashMap<String, String> user = db.getUserDetails();

    String name = user.get("name");
    String email = user.get("email");

    // Displaying the user details on the screen
    txtName.setText(name);
    txtEmail.setText(email);

    // Logout button click event
    btnLogout.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            logoutUser();
          }
        });

    // Link to Image Screen
    btnLinkToImage.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), ImageActivity.class);
            startActivity(i);
            finish();
          }
        });

    // Link to Weather Screen
    btnLinkToWeather.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), WeatherActivity.class);
            startActivity(i);
            finish();
          }
        });
  }