Solved

how to hold the previous value used in android

Posted on 2013-01-21
7
433 Views
Last Modified: 2013-02-04
can somebody tell me how to hold the previous string value in the current session in android



I have a scenario where i pass a string on the click event, i need to keep that id for the doing some other operation in the current session
0
Comment
Question by:roy_sanu
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:PCableGuy
ID: 38803624
You can make a global class which can have "Getters" and "Setters" to Get and Set a String by extending the Application class.

Read Section 2. By Extending the Application class
http://androidresearch.wordpress.com/2012/03/22/defining-global-variables-in-android/


You can also pass a Bundle to an Activity, which is a method to pass variables between Activities.
http://miragemiko.wordpress.com/2010/03/20/android-using-bundle-for-sharing-variables/
0
 

Author Comment

by:roy_sanu
ID: 38810330
my question if i want to hold the same string value  for the next session how i can do that.

for example

"Let say i had a text and a button. i passed some value and pressed the click button it gave me some output, now i need to hold that immediate previous value to do some other operation or validation, let me know how to do that"
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 38811900
you can, write it to a file
or write to xml
or write to database

then retrieve it when you need it
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 15

Expert Comment

by:Ess Kay
ID: 38811908
or if its just from a function, make the function return something

here is psudocide



int x = 5
int y =  functionbla (x)

[now you have two values!! YAY]
0
 
LVL 12

Expert Comment

by:PCableGuy
ID: 38812569
roy_sanu,

Before you change the value, you need to put the current value in a String variable. This could be at the top of your click event before the text is changed. Be careful of the scope of the String variable. In other words if you declare it in the click event, then its scope is only in the click event. If you declare it as a Class variable, then it is global to the Class.

Assuming the text box has the value that you want to save and it's an EditText named editText1:

//Find the textbox
EditText etxt = (EditText) this.findViewById(R.id.editText1);                   
//Save the current text value in currentValue
String currentValue = etxt.getText().toString();
0
 

Accepted Solution

by:
roy_sanu earned 0 total points
ID: 38838474
Any way i have used preferences to hold the data from my previous session that sounds me good enough

Thanks
0
 

Author Closing Comment

by:roy_sanu
ID: 38850517
Holding the previous session using preferences of android  is the  best  solution
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Office365 Intune 6 85
Xamarin 10 49
Way to decrease size of apk file 9 70
Calendar and Email kept in Andriod 6 35
Android SDK is used for creating an android software application. It includes document and tools which are necessary to develop applications with java. In fact Android SDK is harder than other software infrastructure, because there is a virtual devi…
Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question