Last active
November 30, 2017 07:50
-
-
Save omayib/a1f6e9886a972395362859ecb0591951 to your computer and use it in GitHub Desktop.
kuliah pemrograman android untuk kasus login page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.presentasi.loginpage; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
public class MainActivity extends AppCompatActivity { | |
private static final String TAG = "MainActivity"; | |
Button buttonLogin; | |
EditText editTextEmail, editTextPassword; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
editTextEmail = (EditText) findViewById(R.id.editTextEmail); | |
editTextPassword = (EditText) findViewById(R.id.editTextPwd); | |
buttonLogin = (Button) findViewById(R.id.buttonLogin); | |
buttonLogin.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
processLogin(); | |
} | |
}); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
SharedPreferences sharedPreferences = getSharedPreferences("temporary_data",0); | |
boolean isLogin = sharedPreferences.getBoolean("is_login",false); | |
if (isLogin){ | |
Intent nextPageIntent = new Intent(this, DashboardActivity.class); | |
startActivity(nextPageIntent); | |
finish(); | |
} | |
} | |
private void processLogin() { | |
String email = editTextEmail.getText().toString(); | |
String password = editTextPassword.getText().toString(); | |
if (email.equalsIgnoreCase("[email protected]") && password.equalsIgnoreCase("qqq")){ | |
SharedPreferences sharedPreferences = getSharedPreferences("temporary_data",0); | |
sharedPreferences.edit().putBoolean("is_login",true).commit(); | |
Intent nextPageIntent = new Intent(this, DashboardActivity.class); | |
startActivity(nextPageIntent); | |
finish(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment