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.
H开发者_开发百科owever 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?
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.
Pass the number as an extra: https://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String,%20android.os.Parcelable[])
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
精彩评论