Heip me out with these intent - sharing
I'm new to android studio and going through intents. I'm creating a registration app which takes user information in first 4 activities and display them altogether in respective views the 5th activity.
My app has personal, professional,address and other detailed activities that are to be retrieved from edit texts and later displayed on the very last screen.
I can only retrieve data only on the next consecutive screen but not save them and add to last activity later on.
Is there any way that i can do the storing and retrieving part using only intents between 2 activities that are not consecutive to each other ? Any help will be appreciated...!!
java
add a comment |
I'm new to android studio and going through intents. I'm creating a registration app which takes user information in first 4 activities and display them altogether in respective views the 5th activity.
My app has personal, professional,address and other detailed activities that are to be retrieved from edit texts and later displayed on the very last screen.
I can only retrieve data only on the next consecutive screen but not save them and add to last activity later on.
Is there any way that i can do the storing and retrieving part using only intents between 2 activities that are not consecutive to each other ? Any help will be appreciated...!!
java
You can useSharedPreferenceand if you have more data then useDatabase.
– Piyush
Nov 15 '18 at 7:51
you can use general variables inside Application class, declare a class that extend Application and assign it to your app in manifest
– Farrokh
Nov 15 '18 at 7:54
You can obviously save the data that you have retrieved from previous activity. Just store it in some variable and pass that data and the current activity data to next activity, just like that on 5th activity you will have all 4 activities data.
– ManishPrajapati
Nov 15 '18 at 7:54
add a comment |
I'm new to android studio and going through intents. I'm creating a registration app which takes user information in first 4 activities and display them altogether in respective views the 5th activity.
My app has personal, professional,address and other detailed activities that are to be retrieved from edit texts and later displayed on the very last screen.
I can only retrieve data only on the next consecutive screen but not save them and add to last activity later on.
Is there any way that i can do the storing and retrieving part using only intents between 2 activities that are not consecutive to each other ? Any help will be appreciated...!!
java
I'm new to android studio and going through intents. I'm creating a registration app which takes user information in first 4 activities and display them altogether in respective views the 5th activity.
My app has personal, professional,address and other detailed activities that are to be retrieved from edit texts and later displayed on the very last screen.
I can only retrieve data only on the next consecutive screen but not save them and add to last activity later on.
Is there any way that i can do the storing and retrieving part using only intents between 2 activities that are not consecutive to each other ? Any help will be appreciated...!!
java
java
asked Nov 15 '18 at 7:49
Kavee NalluriKavee Nalluri
162
162
You can useSharedPreferenceand if you have more data then useDatabase.
– Piyush
Nov 15 '18 at 7:51
you can use general variables inside Application class, declare a class that extend Application and assign it to your app in manifest
– Farrokh
Nov 15 '18 at 7:54
You can obviously save the data that you have retrieved from previous activity. Just store it in some variable and pass that data and the current activity data to next activity, just like that on 5th activity you will have all 4 activities data.
– ManishPrajapati
Nov 15 '18 at 7:54
add a comment |
You can useSharedPreferenceand if you have more data then useDatabase.
– Piyush
Nov 15 '18 at 7:51
you can use general variables inside Application class, declare a class that extend Application and assign it to your app in manifest
– Farrokh
Nov 15 '18 at 7:54
You can obviously save the data that you have retrieved from previous activity. Just store it in some variable and pass that data and the current activity data to next activity, just like that on 5th activity you will have all 4 activities data.
– ManishPrajapati
Nov 15 '18 at 7:54
You can use
SharedPreference and if you have more data then use Database.– Piyush
Nov 15 '18 at 7:51
You can use
SharedPreference and if you have more data then use Database.– Piyush
Nov 15 '18 at 7:51
you can use general variables inside Application class, declare a class that extend Application and assign it to your app in manifest
– Farrokh
Nov 15 '18 at 7:54
you can use general variables inside Application class, declare a class that extend Application and assign it to your app in manifest
– Farrokh
Nov 15 '18 at 7:54
You can obviously save the data that you have retrieved from previous activity. Just store it in some variable and pass that data and the current activity data to next activity, just like that on 5th activity you will have all 4 activities data.
– ManishPrajapati
Nov 15 '18 at 7:54
You can obviously save the data that you have retrieved from previous activity. Just store it in some variable and pass that data and the current activity data to next activity, just like that on 5th activity you will have all 4 activities data.
– ManishPrajapati
Nov 15 '18 at 7:54
add a comment |
5 Answers
5
active
oldest
votes
Yes you can do so by sending the data form one activity to the other activity in chain.
Let say your app starts at ActivityOne then goes to ActivityTwo then to ActivityThree then to ActivityFour then to ActivityFive and submits the data here in ActivityFive. Each activity has a EditText to enter data and a button which on clicking goes to the next activity.
In ActivityOne create and then start an intent on the button click i.e. inside onClick():
Intent i = new Intent(ActivityOne.this,ActivityTwo.class);
i.putExtra("Name",edittext.getText().toString());//get sting from 1st edittext
startActivity(i);
Now your second activity has been started i.e. ActivityTwo.
In that activities onCreate() method create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the following:
Intent i = new Intent(ActivityTwo.this,ActivityThree.class);
i.putExtra("Address",edittextTwo.getText().toString());//This line fetches the data from the activities edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Now in the third activity which has been started i.e. ActivityThree.
Do the same thing in the activities onCreate() method i.e. create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the same thing that you did previously but also fetch the data passed from the previous activity:
Intent i = new Intent(ActivityThree.this,ActivityFour.class);
i.putExtra("email",edittextThree.getText().toString());//This line fetches the data from the activity's edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
i.putExtra("Address", a.getStringExtra("Address"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Continue this in all the activities and in the end you will be able to get all the data in the final activity.
The logic here is to pass the data from one activity to the other and keep on adding data on the go.
thanks a lot . this helped me . but how can i put the data fetched from all data views into seperate textviews in the last activity ?
– Kavee Nalluri
Nov 16 '18 at 6:52
Store the data in some local variables eg:String name = a.getStringExtra("Name");and thennameTextView.setText(name);
– Sayok Majumder
Nov 16 '18 at 7:36
add a comment |
There are many ways to pass the data.One easy and efficient way to implement.create a public class in your package.In that class declare your values as static like below.
public class MyDataClass
public static String name;
public static String userid;
you can pass the values like below
MyDataClass myobj=new MyDataClass();
myobj.name="Jhon";
myobj.username="Jhon@gmail.com";
To fetch the value from anywhere Activity or fragment use this
String val=myobj.name;
String val=myobj.username;
add a comment |
You can use singleton class
Create one model class and add the data from that four activites
public class MySingleton
private UserModel user_details;
private static MySingleton ourInstance = new MySingleton();
public static MySingleton getInstance()
return ourInstance;
private MySingleton()
public void setUserDetails(UserModel news)
this.user_details= news;
public UserModel getUserDetails()
return user_details;
//add user details
MySingleton mysingleton= MySingleton .getInstance();
mysingleton.setUserDetails(userdetails); // userdetails - model class object
add a comment |
Use SharedPreference to save your data using key-value pairs. And then you can retrieve the data in any activity using the respective key. Just make sure you use the proper key to save a variable.
public SharedPreferences sharedPref;
public SharedPreferences.Editor editor;
sharedPref = getSharedPreferences("name_of_your_preference", Context.MODE_PRIVATE);
editor = sharedPref.edit();
editor.putString("key" , "value"); //use to save a value
editor.commit();
sharedPref.getString("key", null); // retrieve the data
add a comment |
I'm also new but why not create One Activity which hold the DataModels and collect the UserInformation within Fragments and set them to the Activity on nextBtnClick?
Something like this:
final Button nextFragmentButton = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
((MyActivity)getActivity()).setUserDataModel(dataModel)
);
Isnt it a bad design, if you have a lot of activities and put data thru them?
If you would use Fragments, the root activity could hold all the data and would datahandling simplify.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314631%2fheip-me-out-with-these-intent-sharing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes you can do so by sending the data form one activity to the other activity in chain.
Let say your app starts at ActivityOne then goes to ActivityTwo then to ActivityThree then to ActivityFour then to ActivityFive and submits the data here in ActivityFive. Each activity has a EditText to enter data and a button which on clicking goes to the next activity.
In ActivityOne create and then start an intent on the button click i.e. inside onClick():
Intent i = new Intent(ActivityOne.this,ActivityTwo.class);
i.putExtra("Name",edittext.getText().toString());//get sting from 1st edittext
startActivity(i);
Now your second activity has been started i.e. ActivityTwo.
In that activities onCreate() method create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the following:
Intent i = new Intent(ActivityTwo.this,ActivityThree.class);
i.putExtra("Address",edittextTwo.getText().toString());//This line fetches the data from the activities edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Now in the third activity which has been started i.e. ActivityThree.
Do the same thing in the activities onCreate() method i.e. create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the same thing that you did previously but also fetch the data passed from the previous activity:
Intent i = new Intent(ActivityThree.this,ActivityFour.class);
i.putExtra("email",edittextThree.getText().toString());//This line fetches the data from the activity's edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
i.putExtra("Address", a.getStringExtra("Address"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Continue this in all the activities and in the end you will be able to get all the data in the final activity.
The logic here is to pass the data from one activity to the other and keep on adding data on the go.
thanks a lot . this helped me . but how can i put the data fetched from all data views into seperate textviews in the last activity ?
– Kavee Nalluri
Nov 16 '18 at 6:52
Store the data in some local variables eg:String name = a.getStringExtra("Name");and thennameTextView.setText(name);
– Sayok Majumder
Nov 16 '18 at 7:36
add a comment |
Yes you can do so by sending the data form one activity to the other activity in chain.
Let say your app starts at ActivityOne then goes to ActivityTwo then to ActivityThree then to ActivityFour then to ActivityFive and submits the data here in ActivityFive. Each activity has a EditText to enter data and a button which on clicking goes to the next activity.
In ActivityOne create and then start an intent on the button click i.e. inside onClick():
Intent i = new Intent(ActivityOne.this,ActivityTwo.class);
i.putExtra("Name",edittext.getText().toString());//get sting from 1st edittext
startActivity(i);
Now your second activity has been started i.e. ActivityTwo.
In that activities onCreate() method create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the following:
Intent i = new Intent(ActivityTwo.this,ActivityThree.class);
i.putExtra("Address",edittextTwo.getText().toString());//This line fetches the data from the activities edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Now in the third activity which has been started i.e. ActivityThree.
Do the same thing in the activities onCreate() method i.e. create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the same thing that you did previously but also fetch the data passed from the previous activity:
Intent i = new Intent(ActivityThree.this,ActivityFour.class);
i.putExtra("email",edittextThree.getText().toString());//This line fetches the data from the activity's edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
i.putExtra("Address", a.getStringExtra("Address"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Continue this in all the activities and in the end you will be able to get all the data in the final activity.
The logic here is to pass the data from one activity to the other and keep on adding data on the go.
thanks a lot . this helped me . but how can i put the data fetched from all data views into seperate textviews in the last activity ?
– Kavee Nalluri
Nov 16 '18 at 6:52
Store the data in some local variables eg:String name = a.getStringExtra("Name");and thennameTextView.setText(name);
– Sayok Majumder
Nov 16 '18 at 7:36
add a comment |
Yes you can do so by sending the data form one activity to the other activity in chain.
Let say your app starts at ActivityOne then goes to ActivityTwo then to ActivityThree then to ActivityFour then to ActivityFive and submits the data here in ActivityFive. Each activity has a EditText to enter data and a button which on clicking goes to the next activity.
In ActivityOne create and then start an intent on the button click i.e. inside onClick():
Intent i = new Intent(ActivityOne.this,ActivityTwo.class);
i.putExtra("Name",edittext.getText().toString());//get sting from 1st edittext
startActivity(i);
Now your second activity has been started i.e. ActivityTwo.
In that activities onCreate() method create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the following:
Intent i = new Intent(ActivityTwo.this,ActivityThree.class);
i.putExtra("Address",edittextTwo.getText().toString());//This line fetches the data from the activities edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Now in the third activity which has been started i.e. ActivityThree.
Do the same thing in the activities onCreate() method i.e. create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the same thing that you did previously but also fetch the data passed from the previous activity:
Intent i = new Intent(ActivityThree.this,ActivityFour.class);
i.putExtra("email",edittextThree.getText().toString());//This line fetches the data from the activity's edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
i.putExtra("Address", a.getStringExtra("Address"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Continue this in all the activities and in the end you will be able to get all the data in the final activity.
The logic here is to pass the data from one activity to the other and keep on adding data on the go.
Yes you can do so by sending the data form one activity to the other activity in chain.
Let say your app starts at ActivityOne then goes to ActivityTwo then to ActivityThree then to ActivityFour then to ActivityFive and submits the data here in ActivityFive. Each activity has a EditText to enter data and a button which on clicking goes to the next activity.
In ActivityOne create and then start an intent on the button click i.e. inside onClick():
Intent i = new Intent(ActivityOne.this,ActivityTwo.class);
i.putExtra("Name",edittext.getText().toString());//get sting from 1st edittext
startActivity(i);
Now your second activity has been started i.e. ActivityTwo.
In that activities onCreate() method create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the following:
Intent i = new Intent(ActivityTwo.this,ActivityThree.class);
i.putExtra("Address",edittextTwo.getText().toString());//This line fetches the data from the activities edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Now in the third activity which has been started i.e. ActivityThree.
Do the same thing in the activities onCreate() method i.e. create an IntentIntent a = getIntent();
Now in onClick method for the button of this activity do the same thing that you did previously but also fetch the data passed from the previous activity:
Intent i = new Intent(ActivityThree.this,ActivityFour.class);
i.putExtra("email",edittextThree.getText().toString());//This line fetches the data from the activity's edittext
i.putExtra("Name", a.getStringExtra("Name"));//This line fetches the data from the intent which called this activity.
i.putExtra("Address", a.getStringExtra("Address"));//This line fetches the data from the intent which called this activity.
startActivity(i);
Continue this in all the activities and in the end you will be able to get all the data in the final activity.
The logic here is to pass the data from one activity to the other and keep on adding data on the go.
answered Nov 15 '18 at 8:57
Sayok MajumderSayok Majumder
330114
330114
thanks a lot . this helped me . but how can i put the data fetched from all data views into seperate textviews in the last activity ?
– Kavee Nalluri
Nov 16 '18 at 6:52
Store the data in some local variables eg:String name = a.getStringExtra("Name");and thennameTextView.setText(name);
– Sayok Majumder
Nov 16 '18 at 7:36
add a comment |
thanks a lot . this helped me . but how can i put the data fetched from all data views into seperate textviews in the last activity ?
– Kavee Nalluri
Nov 16 '18 at 6:52
Store the data in some local variables eg:String name = a.getStringExtra("Name");and thennameTextView.setText(name);
– Sayok Majumder
Nov 16 '18 at 7:36
thanks a lot . this helped me . but how can i put the data fetched from all data views into seperate textviews in the last activity ?
– Kavee Nalluri
Nov 16 '18 at 6:52
thanks a lot . this helped me . but how can i put the data fetched from all data views into seperate textviews in the last activity ?
– Kavee Nalluri
Nov 16 '18 at 6:52
Store the data in some local variables eg:
String name = a.getStringExtra("Name"); and then nameTextView.setText(name);– Sayok Majumder
Nov 16 '18 at 7:36
Store the data in some local variables eg:
String name = a.getStringExtra("Name"); and then nameTextView.setText(name);– Sayok Majumder
Nov 16 '18 at 7:36
add a comment |
There are many ways to pass the data.One easy and efficient way to implement.create a public class in your package.In that class declare your values as static like below.
public class MyDataClass
public static String name;
public static String userid;
you can pass the values like below
MyDataClass myobj=new MyDataClass();
myobj.name="Jhon";
myobj.username="Jhon@gmail.com";
To fetch the value from anywhere Activity or fragment use this
String val=myobj.name;
String val=myobj.username;
add a comment |
There are many ways to pass the data.One easy and efficient way to implement.create a public class in your package.In that class declare your values as static like below.
public class MyDataClass
public static String name;
public static String userid;
you can pass the values like below
MyDataClass myobj=new MyDataClass();
myobj.name="Jhon";
myobj.username="Jhon@gmail.com";
To fetch the value from anywhere Activity or fragment use this
String val=myobj.name;
String val=myobj.username;
add a comment |
There are many ways to pass the data.One easy and efficient way to implement.create a public class in your package.In that class declare your values as static like below.
public class MyDataClass
public static String name;
public static String userid;
you can pass the values like below
MyDataClass myobj=new MyDataClass();
myobj.name="Jhon";
myobj.username="Jhon@gmail.com";
To fetch the value from anywhere Activity or fragment use this
String val=myobj.name;
String val=myobj.username;
There are many ways to pass the data.One easy and efficient way to implement.create a public class in your package.In that class declare your values as static like below.
public class MyDataClass
public static String name;
public static String userid;
you can pass the values like below
MyDataClass myobj=new MyDataClass();
myobj.name="Jhon";
myobj.username="Jhon@gmail.com";
To fetch the value from anywhere Activity or fragment use this
String val=myobj.name;
String val=myobj.username;
answered Nov 15 '18 at 9:49
Syed Danish HaiderSyed Danish Haider
474311
474311
add a comment |
add a comment |
You can use singleton class
Create one model class and add the data from that four activites
public class MySingleton
private UserModel user_details;
private static MySingleton ourInstance = new MySingleton();
public static MySingleton getInstance()
return ourInstance;
private MySingleton()
public void setUserDetails(UserModel news)
this.user_details= news;
public UserModel getUserDetails()
return user_details;
//add user details
MySingleton mysingleton= MySingleton .getInstance();
mysingleton.setUserDetails(userdetails); // userdetails - model class object
add a comment |
You can use singleton class
Create one model class and add the data from that four activites
public class MySingleton
private UserModel user_details;
private static MySingleton ourInstance = new MySingleton();
public static MySingleton getInstance()
return ourInstance;
private MySingleton()
public void setUserDetails(UserModel news)
this.user_details= news;
public UserModel getUserDetails()
return user_details;
//add user details
MySingleton mysingleton= MySingleton .getInstance();
mysingleton.setUserDetails(userdetails); // userdetails - model class object
add a comment |
You can use singleton class
Create one model class and add the data from that four activites
public class MySingleton
private UserModel user_details;
private static MySingleton ourInstance = new MySingleton();
public static MySingleton getInstance()
return ourInstance;
private MySingleton()
public void setUserDetails(UserModel news)
this.user_details= news;
public UserModel getUserDetails()
return user_details;
//add user details
MySingleton mysingleton= MySingleton .getInstance();
mysingleton.setUserDetails(userdetails); // userdetails - model class object
You can use singleton class
Create one model class and add the data from that four activites
public class MySingleton
private UserModel user_details;
private static MySingleton ourInstance = new MySingleton();
public static MySingleton getInstance()
return ourInstance;
private MySingleton()
public void setUserDetails(UserModel news)
this.user_details= news;
public UserModel getUserDetails()
return user_details;
//add user details
MySingleton mysingleton= MySingleton .getInstance();
mysingleton.setUserDetails(userdetails); // userdetails - model class object
edited Nov 15 '18 at 10:03
answered Nov 15 '18 at 9:29
veerendranveerendran
364
364
add a comment |
add a comment |
Use SharedPreference to save your data using key-value pairs. And then you can retrieve the data in any activity using the respective key. Just make sure you use the proper key to save a variable.
public SharedPreferences sharedPref;
public SharedPreferences.Editor editor;
sharedPref = getSharedPreferences("name_of_your_preference", Context.MODE_PRIVATE);
editor = sharedPref.edit();
editor.putString("key" , "value"); //use to save a value
editor.commit();
sharedPref.getString("key", null); // retrieve the data
add a comment |
Use SharedPreference to save your data using key-value pairs. And then you can retrieve the data in any activity using the respective key. Just make sure you use the proper key to save a variable.
public SharedPreferences sharedPref;
public SharedPreferences.Editor editor;
sharedPref = getSharedPreferences("name_of_your_preference", Context.MODE_PRIVATE);
editor = sharedPref.edit();
editor.putString("key" , "value"); //use to save a value
editor.commit();
sharedPref.getString("key", null); // retrieve the data
add a comment |
Use SharedPreference to save your data using key-value pairs. And then you can retrieve the data in any activity using the respective key. Just make sure you use the proper key to save a variable.
public SharedPreferences sharedPref;
public SharedPreferences.Editor editor;
sharedPref = getSharedPreferences("name_of_your_preference", Context.MODE_PRIVATE);
editor = sharedPref.edit();
editor.putString("key" , "value"); //use to save a value
editor.commit();
sharedPref.getString("key", null); // retrieve the data
Use SharedPreference to save your data using key-value pairs. And then you can retrieve the data in any activity using the respective key. Just make sure you use the proper key to save a variable.
public SharedPreferences sharedPref;
public SharedPreferences.Editor editor;
sharedPref = getSharedPreferences("name_of_your_preference", Context.MODE_PRIVATE);
editor = sharedPref.edit();
editor.putString("key" , "value"); //use to save a value
editor.commit();
sharedPref.getString("key", null); // retrieve the data
edited Nov 15 '18 at 10:28
answered Nov 15 '18 at 10:21
chetnachetna
795
795
add a comment |
add a comment |
I'm also new but why not create One Activity which hold the DataModels and collect the UserInformation within Fragments and set them to the Activity on nextBtnClick?
Something like this:
final Button nextFragmentButton = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
((MyActivity)getActivity()).setUserDataModel(dataModel)
);
Isnt it a bad design, if you have a lot of activities and put data thru them?
If you would use Fragments, the root activity could hold all the data and would datahandling simplify.
add a comment |
I'm also new but why not create One Activity which hold the DataModels and collect the UserInformation within Fragments and set them to the Activity on nextBtnClick?
Something like this:
final Button nextFragmentButton = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
((MyActivity)getActivity()).setUserDataModel(dataModel)
);
Isnt it a bad design, if you have a lot of activities and put data thru them?
If you would use Fragments, the root activity could hold all the data and would datahandling simplify.
add a comment |
I'm also new but why not create One Activity which hold the DataModels and collect the UserInformation within Fragments and set them to the Activity on nextBtnClick?
Something like this:
final Button nextFragmentButton = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
((MyActivity)getActivity()).setUserDataModel(dataModel)
);
Isnt it a bad design, if you have a lot of activities and put data thru them?
If you would use Fragments, the root activity could hold all the data and would datahandling simplify.
I'm also new but why not create One Activity which hold the DataModels and collect the UserInformation within Fragments and set them to the Activity on nextBtnClick?
Something like this:
final Button nextFragmentButton = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
((MyActivity)getActivity()).setUserDataModel(dataModel)
);
Isnt it a bad design, if you have a lot of activities and put data thru them?
If you would use Fragments, the root activity could hold all the data and would datahandling simplify.
edited Nov 16 '18 at 10:01
answered Nov 15 '18 at 7:59
John DoeJohn Doe
86129
86129
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314631%2fheip-me-out-with-these-intent-sharing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can use
SharedPreferenceand if you have more data then useDatabase.– Piyush
Nov 15 '18 at 7:51
you can use general variables inside Application class, declare a class that extend Application and assign it to your app in manifest
– Farrokh
Nov 15 '18 at 7:54
You can obviously save the data that you have retrieved from previous activity. Just store it in some variable and pass that data and the current activity data to next activity, just like that on 5th activity you will have all 4 activities data.
– ManishPrajapati
Nov 15 '18 at 7:54