Practical 18
activity_login.xml
<?xml version="1.0" encoding="utf-8"?> android:layout_width="match_parent"
<RelativeLayout
xmlns:android="[Link] android:layout_height="wrap_content"/>
pk/res/android"
android:background="#1A237E" <EditText
android:layout_width="match_parent" android:id="@+id/pass"
android:layout_height="match_parent"> android:hint="Password"
android:inputType="textPassword"
<LinearLayout android:textColor="#fff"
android:orientation="vertical" android:textColorHint="#DDFFFFFF"
android:background="#33FFFFFF" android:layout_marginTop="12dp"
android:padding="24dp" android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_margin="30dp" android:layout_height="wrap_content"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"> <CheckBox
android:id="@+id/remember"
<TextView android:text="Remember Me"
android:text="Login" android:textColor="#fff"
android:textSize="28sp" android:layout_marginTop="10dp"
android:textStyle="bold" android:layout_width="wrap_content"
android:textColor="#ffffff"
android:gravity="center" android:layout_height="wrap_content"/>
android:layout_width="match_parent"
<Button
android:layout_height="wrap_content"/> android:id="@+id/loginBtn"
android:text="LOGIN"
<EditText android:layout_marginTop="18dp"
android:id="@+id/email" android:layout_width="match_parent"
android:hint="Email" android:layout_height="50dp"/>
android:textColor="#fff" </LinearLayout>
android:textColorHint="#DDFFFFFF"
android:layout_marginTop="20dp" </RelativeLayout>
activity_home.xml
<?xml version="1.0" encoding="utf-8"?> android:textColor="#fff"
<LinearLayout android:textSize="26sp"
xmlns:android="[Link] android:layout_marginBottom="30dp"
pk/res/android" android:layout_width="wrap_content"
android:gravity="center" android:layout_height="wrap_content"/>
android:orientation="vertical"
android:background="#0D47A1" <Button
android:layout_width="match_parent" android:id="@+id/logout"
android:layout_height="match_parent"> android:text="LOGOUT"
android:layout_width="200dp"
<TextView android:layout_height="50dp"/>
android:text="Welcome User " </LinearLayout>
[Link]
package [Link];
// auto login
import [Link]; if([Link]("logged",false)){
import [Link]; startActivity(new
import [Link]; Intent(this,[Link]));
import [Link]; finish();
import [Link].*; }
import
[Link];
findViewById([Link]).setOnClickListe
public class LoginActivity extends ner(v->{
AppCompatActivity {
EditText email,pass; if([Link]().toString().equals("Ayush")
CheckBox remember; &&
SharedPreferences sp;
[Link]().toString().equals("1234")){
protected void onCreate(Bundle b){
[Link](b); if([Link]())
setContentView([Link].activity_login);
Log.d("LIFECYCLE","Login onCreate"); [Link]().putBoolean("logged",true).apply();
email=findViewById([Link]); startActivity(new
pass=findViewById([Link]); Intent(this,[Link]));
finish();
remember=findViewById([Link]); }
else
[Link](this,"Wrong
sp=getSharedPreferences("login",MODE_PRI Credentials",Toast.LENGTH_SHORT).show(
VATE); );
}); onPause(){[Link]();Log.d("LIFECYC
} LE","Login onPause");}
protected void
protected void onStop(){[Link]();Log.d("LIFECYCLE",
onStart(){[Link]();Log.d("LIFECYCLE "Login onStop");}
","Login onStart");} protected void
protected void onDestroy(){[Link]();Log.d("LIFEC
onResume(){[Link]();Log.d("LIFEC YCLE","Login onDestroy");}
YCLE","Login onResume");} }
protected void
[Link]
package [Link]; VATE);
[Link]().clear().apply();
import [Link]; startActivity(new
import [Link]; Intent(this,[Link]));
import [Link]; finish();
import [Link]; });
import [Link]; }
import
[Link]; protected void
onStart(){[Link]();Log.d("LIFECYCLE
public class HomeActivity extends ","Home onStart");}
AppCompatActivity { protected void
onResume(){[Link]();Log.d("LIFEC
protected void onCreate(Bundle b){ YCLE","Home onResume");}
[Link](b); protected void
setContentView([Link].activity_home); onPause(){[Link]();Log.d("LIFECYC
Log.d("LIFECYCLE","Home onCreate"); LE","Home onPause");}
protected void
Button onStop(){[Link]();Log.d("LIFECYCLE",
logout=findViewById([Link]); "Home onStop");}
protected void
[Link](v->{ onDestroy(){[Link]();Log.d("LIFEC
SharedPreferences YCLE","Home onDestroy");}
sp=getSharedPreferences("login",MODE_PRI }