问题描述
我拼命试图让我的头部包裹着如何实现主屏幕小部件。现在,我(终于)能够得到的一个按钮preSS建立在清单的意图过滤器我小部件响应按钮。
I am desperately trying to get my head wrapped around how to implement home screen widgets. Right now, I (finally) was able to get a button on my widget respond to a button press setting up an intent filter in the manifest.
不过,我不能为我的生活弄清楚如何启动活动按钮时,pssed $ P $。基本上,这里的code,我有:
However, I cannot for the life of me figure out how to launch an activity when the button is pressed. Basically, here's the code i have:
@Override
public void onReceive(Context context, Intent intent)
{
super.onReceive(context, intent);
if(intent.getAction().equals("com.bic.search.searchWidget.CLICK"))
{
Toast.makeText(context, "It works!!", Toast.LENGTH_SHORT).show();
}
}
我真正想做的事情,虽然是开始一个新的活动,不显示敬酒消息。我知道它是与未决的意图,但我无法弄清楚如何得到那个工作。
What I really want to do, though, is start a new activity, not display a toast message. I know it has something to do with pending intents, but I can't figure out how to get that to work.
任何帮助和样品code将AP preciated。由于一吨到谁回答了这个!
Any help and sample code would be appreciated. Thanks a ton to whoever answers this!
推荐答案
那么,你的应用程序插件应该已经有一个 PendingIntent
你绑到按钮。取而代之的是 PendingIntent
触发一个的BroadcastReceiver
,让它成为一个 PendingIntent
启动了一个活动
。
Well, your app widget should already have a PendingIntent
that you tied to the button. Instead of a PendingIntent
that triggers a BroadcastReceiver
, have it be a PendingIntent
that starts up an Activity
.
这篇关于如何从Android主屏幕小部件发起活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!