Android Manifest.xml
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.sparity.visitmdnow">
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".SplashActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity
- android:name=".LoginActivity"
- android:screenOrientation="portrait"
- android:windowSoftInputMode="adjustPan|stateHidden" />
- <activity
- android:name=".HomeActivity"
- android:screenOrientation="portrait"
- android:windowSoftInputMode="adjustPan|stateHidden" />
- <service android:name=".notification.MyFirebaseMessagingService">
- <intent-filter>
- <action android:name="com.google.firebase.MESSAGING_EVENT" />
- </intent-filter>
- </service>
- <service android:name=".notification.FirebaseIDService">
- <intent-filter>
- <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
- </intent-filter>
- </service>
- </application>
- </manifest>
activity_main.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/pageLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context="com.example.saketh.sharedprefdemo.MainActivity">
- <Switch
- android:id="@+id/pageColorSwitch"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="20dp"
- android:text="True Green" />
- <EditText
- android:id="@+id/etName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="74dp"
- android:hint="Eneter your name" />
- <EditText
- android:id="@+id/etProfession"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter your professional" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:onClick="saveAccountData"
- android:text="save" />
- <Button
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:onClick="loadAccountData"
- android:text="load" />
- </LinearLayout>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:onClick="openSecondActivity"
- android:text="open second activity" />
- <TextView
- android:id="@+id/txvName"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:text="Person Name"
- android:textColor="#969494"
- android:textSize="25sp"
- android:textStyle="bold" />
- <TextView
- android:id="@+id/txvProfession"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:text="Profession"
- android:textColor="#969494"
- android:textSize="25sp"
- android:textStyle="bold" />
- </LinearLayout>
MainActivity.java
- package com.example.saketh.sharedprefdemo;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.Switch;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- private EditText etName,etProfession;
- private TextView txvName,txvProfession;
- private Switch pageColorSwitch;
- private LinearLayout pageLayout;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- etName=(EditText) findViewById(R.id.etName);
- etProfession=(EditText) findViewById(R.id.etProfession);
- txvName=(TextView) findViewById(R.id.txvName);
- txvProfession=(TextView) findViewById(R.id.txvProfession);
- pageColorSwitch=(Switch) findViewById(R.id.pageColorSwitch);
- pageLayout=(LinearLayout) findViewById(R.id.pageLayout);
- }
- public void saveAccountData(View view) {
- SharedPreferences sharedPreferences=getPreferences(Context.MODE_PRIVATE);
- SharedPreferences.Editor editor=sharedPreferences.edit();
- editor.putString("name",etName.getText().toString());
- editor.putString("profession",etProfession.getText().toString());
- editor.putInt("prof_id",287);
- editor.apply();//editor.commit
- }
- public void loadAccountData(View view) {
- SharedPreferences sharedPreferences=getPreferences(Context.MODE_PRIVATE);
- String name=sharedPreferences.getString("name","N/A");
- String profession=sharedPreferences.getString("profession","N/A");
- int profId=sharedPreferences.getInt("prof_id",0);
- txvName.setText(name);
- String profstr=profession+"-"+profId;
- txvProfession.setText(profstr);
- }
- public void openSecondActivity(View view) {
- Intent in=new Intent(getApplicationContext(),SecondActivitys.class);
- startActivity(in);
- }
- }
activity_second__activitys.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:padding="20dp">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_weight="1"
- android:onClick="loadAccountData"
- android:text="load" />
- <Button
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_weight="1"
- android:onClick="clearAccountData"
- android:text="clear" />
- <Button
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_weight="1"
- android:onClick="removeProfessionKey"
- android:text="remove" />
- </LinearLayout>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginTop="30dp"
- android:text="Person Name"
- android:textColor="#969494"
- android:textSize="24sp"
- android:textStyle="bold" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:text="Profession"
- android:textColor="#969494"
- android:textSize="20sp"
- android:textStyle="bold" />
- </LinearLayout>
SecondActivitys.java
- package com.example.saketh.sharedprefdemo;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- public class SecondActivitys extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_second_activitys);
- }
- public void loadAccountData(View view) {
- }
- public void clearAccountData(View view) {
- }
- public void removeProfessionKey(View view) {
- }
- }
No comments:
Post a Comment