How to create dynamic intent in Android?

I would like to know how I can create a “dynamic intent” in android.

In the end, I want to show a list of data items that are cut from the web service, and when the item is clicked, to start a new action with some set parameters. Please note that all elements will be an instance of the same class, which, I believe, will expand Activiy.

I managed to list the elements, but cannot find a way to make part of the "dynamic intention".

I know that the following code does not work, but it illustrates what I'm trying to execute.

I hope I understand what I understand.

if (((TextView) view).getText().equals("Page")) { MyClass item = new MyClass("foo", "bar"); myIntent = new Intent(view.getContext(), item); } 

Thanks.

+4
source share
2 answers

You can send any custom or “dynamic” content using additional features. They are available for activities that run on purpose.

so that you do something like:

 myIntent.putExtra("myCutsomDataTag","myCustomData"); 

about what you run.

In your host activity you will do something like:

 Intent launchIntent = getIntent(); String myCustomData = launchIntent.getStringExtra("myCutsomDataTag"); 
+2
source

Perhaps you can write a singleton class that stores user data. After starting the activity, you read the data from this singleton ...

J.P.M.

+1
source

All Articles