Donal Rafferty
Donal Rafferty

Reputation: 19826

Sending data from a class to an activity?

Have a question about sending data between classes and activities.

I currently have a class that monitors outgoing class and gets the number of an outgoing call.

I instantiate this class in my main Activity and run its method that retrieves the number.

However I now have another Activity that I want to pass the number to.

I start this Activity through an Intent from the class that gets the number.

So it works like this:

MainActiviy Starts > Starts Object that listens for outgoing call > outgoing call detected > Object gets outgoing number > object fires Intent to create new Activity after outgoing call logged and number retrieved > new Activity displays

I hope that is a bit clearer?

So I want to send the number from the class (object) to the new Activity that it has started.

So what is the simplest way to do this?

Upvotes: 1

Views: 1723

Answers (3)

jinais
jinais

Reputation: 33

For a different approach without bundling your data to the intent, you can try the GNLauncher component of the following library I wrote to make this taks simpler when there is a number of objects to be passed in and with different objectives. https://github.com/noxiouswinter/gnlib_android/wiki#gnlauncher

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006644

Call putExtra() on the Intent you are using with startService(). Use putExtra() to store the phone number in the Intent. Use getExtra() in the service being started to retrieve the phone number.

Upvotes: 3

Related Questions