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.
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.
Any help and sample code would be appreciated. Thanks a ton to whoever answers this!
An activity represents a single screen with a user interface just like window or frame of Java. Android activity is the subclass of ContextThemeWrapper class. If you have worked with C, C++ or Java programming language then you must have seen that your program starts from main() function.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With