473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Shared Preference Android Studio

I had build an mobile app which consist of 2 activity as shown in figure below.It can let user to choose for go to main activity or the second activity

Main activity let user to send text to the second activity.
Second Activity let user to recieve text from main activity.

Can somebody teach me how i can save the text received in the second activity by using shared preference directly. That mean everytime second activity recieved text, it can save the text itself and user dont need to press an save button manually for saving that text

Below shown the layout of my app and code for that 2 activity


Expand|Select|Wrap|Line Numbers
  1. public class MainActivity extends Activity {
  2.  
  3.     EditText SendValue;
  4.     Button SendEditTextValue;
  5.     Intent intent;
  6.     @Override
  7.     protected void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.activity_main);
  10.  
  11.         SendEditTextValue = (Button)findViewById(R.id.button1);
  12.         SendValue = (EditText)findViewById(R.id.editText1);
  13.  
  14.         SendEditTextValue.setOnClickListener(new View.OnClickListener() {
  15.  
  16.             @Override
  17.             public void onClick(View v) {
  18.  
  19.                 intent = new Intent(getApplicationContext(),SecondActivity.class);
  20.                 intent.putExtra("EdiTtEXTvALUE", SendValue.getText().toString());
  21.                 startActivity(intent);
  22.  
  23.             }
  24.         });
  25.     }
  26. }


Expand|Select|Wrap|Line Numbers
  1. public class SecondActivity extends Activity {
  2.  
  3.     TextView receive;
  4.     @Override
  5.     protected void onCreate(Bundle savedInstanceState) {
  6.         super.onCreate(savedInstanceState);
  7.         setContentView(R.layout.activity_second);
  8.  
  9.  
  10.  
  11.  
  12.  
  13.         receive = (TextView)findViewById(R.id.textView1);
  14.  
  15.         receive.setText(getIntent().getStringExtra("EdiTtEXTvALUE"));
  16.  
  17.  
  18.     }
  19.  
  20.  
  21. }
Attached Images
File Type: png App_layout.PNG (7.3 KB, 81 views)
File Type: png MainActivity_layout.PNG (6.0 KB, 60 views)
File Type: png SecondActivity_layout.PNG (7.3 KB, 57 views)
Mar 2 '18 #1
0 1318

Sign in to post your reply or Sign up for a free account.

Similar topics

1
Nepomuk
by: Nepomuk | last post by:
Android development is a pretty broad field and no one article could ever hope to encompass everything there is to learn. For that reason, this article attempts to collect links to various tutorials,...
0
by: robertybob | last post by:
Hi. I am trying to write a basic app in Android Studio (my first attempt). I have an EditText field for a username and one for a password plus a button. I also have a WebView which will contain...
0
gautamz07
by: gautamz07 | last post by:
Hey guys, i am coming on here after a long while :) hope you all been doing fine. I just have a quick question anybody here every used a db like crouchDB to connect to a android application. how do...
0
by: hasnainahmad | last post by:
I am using android studio. While debugging my app I want to jump to the specific frame and start debugging from that frame, skipping the other frames in the frames tab. I want to see the frames...
0
by: 5402702 | last post by:
My question is do I need to have an android SDK package saved to start a new android project, even if I don't want to run it. And do I need the SDK to create an android virtual device in eclipse. My...
5
by: LemonFoam | last post by:
can anybody shown me how to build an step counter app using android studio that will count the number of footstep and plot the number of footstep in graphical form for every 15 minutes?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.