-3

I have two activities, A & B. A has a button to go to B. B sets some parameters using Seekbars.

When I go back to A there is no problem. But, I when again go to B, the Seekbars do not show the changed value.

I tried looking for solutions and I came to know about "Intent" class but the concept is not clear to me.

What is a simple clean solution to see the changed values when going to the Activity B again from Activity A?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

2 Answers2

1

When we want to move between activities, we use Intent. For e.g. If I have two activities ActivityA and ActivityB, I will do something like this:

Intent intent = new Intent (Activity.this, Activity.class) ;
startActivity (intent) ;

But I want to pass some values from one activity to another, Intents are also useful for that. Lets say I want to pass some string value:

In ActivityA (before starting the activity):

 Intent intent = new Intent (Activity.this, Activity.class) ;
 intent.putExtra("key", "value");
 startActivity (intent) ;

And in ActivityB (inside onCreate) :

 Intent intent = getIntent() ;
 String test = intent.getString("key");

And here you have your value. You can also pass objects if you want by implementing serializable/parcelable class. Read about it:

How to pass value using Intent between Activity in android

https://www.javacodegeeks.com/2014/01/android-tutorial-two-methods-of-passing-object-by-intent-serializableparcelable.html

Rahul Mishra
  • 583
  • 7
  • 17
  • Sure. Though my purpose has been fulfilled in another way, since I have C/C++ codes, I am using jni wrappers to update values. But, I will definitely use this for other apps. – Tahsin Ahmed Chowdhury Nov 28 '17 at 00:22
0

You should use intent.putExtra() and intent.getExtra(). You can see the example here; https://stackoverflow.com/a/14017737/8883361

Yusuf Çağlar
  • 320
  • 2
  • 13