android - 将数据从一个类发送到一个 Activity ?

标签 android android-intent android-activity

有关于在类和 Activity 之间发送数据的问题。

我目前有一个类(class)监控呼出类(class)并获取呼出号码。

我在我的主要 Activity 中实例化这个类并运行它的方法来检索数字。

但是我现在有另一个 Activity 我想将号码传递给它。

我通过获取号码的类中的 Intent 启动此 Activity

所以它是这样工作的:

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

我希望这更清楚一点?

所以我想将数字从类(对象)发送到它已经启动的新 Activity

那么最简单的方法是什么?

最佳答案

在您使用 startService()Intent 上调用 putExtra()。使用 putExtra() 将电话号码存储在 Intent 中。在正在启动的服务中使用 getExtra() 获取电话号码。

关于android - 将数据从一个类发送到一个 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2148177/

相关文章:

android - 单个对象可以有多个引用吗?

android - 在android中更新ui线程的最佳方式

android - 使用 Intent 将用户转发到带有预先确定的搜索关键字的 Twitter 应用程序

java - 转到下一页时应用程序崩溃( Intent )

android - 从适配器传递 Intent 时,onActivityResult Intent 为 null

android - onResume() 仅当应用程序通过启动器图标启动时才起作用,而不是在安装时按打开按钮

Android 服务与多个 Activity 交互

android - onTouchListener 切换按钮,忽略第一次按下?

android - 如何将 View 添加到 ViewGroup 中的新 Activity

android - ARC 蓝牙支持