从可运行的发送广播意图
我想从新线程开始发送广播。
这就是我尝试过的:
new Thread(new Runnable() {
public void run() {
//some other code for timing.
// ..
// ..
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(Intent.ACTION_ANSWER);
this.sendBroadcast(broadcastIntent);
}
}).start();
但是我当然需要上下文..这是行不通的。 我该如何处理这个问题。
I want to send a broadcast from a new thread is start.
This is what i tried :
new Thread(new Runnable() {
public void run() {
//some other code for timing.
// ..
// ..
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(Intent.ACTION_ANSWER);
this.sendBroadcast(broadcastIntent);
}
}).start();
But ofcourse i need context..this won't work.
How can i handle this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常做的事情虽然很老套,但如下:
另外,请记住在 Intent 构造函数中包含目标 Java 类。
希望有帮助!
What I usually do, although quite hacky, is the following:
Also, remember to include the target Java class in the Intent constructor.
Hope it helps!
我也面临这个问题。
这是我的解决方案。您要在其中实现此功能的应用程序必须有一个活动。
因此,在该活动中,为其自身创建一个静态变量并将其分配给它。
例如:
现在,在线程中,执行以下操作:
希望这能回答您的问题!
I faced this problem too.
Here is my solution. The application in which you are implementing this must have an Activity.
So, in that Activity, make a static variable of itself and assign this to it.
ex:
Now, in the thread, do this:
hope, this answers your question!