How to launch widget configuration after is been put on screen
My widget launches a configuration screen when chosen to be put on screen. That works fine. I wanted to be able to touch a part of the widget to return to that configuration screen. I have created 2 pending intents in my widget's service but only 开发者_如何学Goone works. The code is below:
remoteView.setOnClickPendingIntent(R.id.my_image,myWidget.makeControlPendingIntent(getApplicationContext(),BUTTON1,appWidgetId));
remoteView.setOnClickPendingIntent(R.id.TextViewBat,myWidget.makeControlPendingIntent(getApplicationContext(),BUTTON2,appWidgetId));
and before those 2 at the beggining of the service the code to choose what to do:
if(command.equals(BUTTON1)){
Intent firstIntent = new Intent(this, anotherActivity.class);
firstIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(firstIntent); //THIS WORKS
}
else if(command.equals(BUTTON2)){
Toast.makeText(getApplicationContext(), "the prefs button is clicked",
Toast.LENGTH_SHORT).show(); //THIS WORKS
/*Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);*/ //THIS WORKS
Intent myIntent = new Intent(this,myConfiguration.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent); //* * * THIS CRASHES * * * *
}
For the life of me i cannot understand how i can launch again the configuration activity. Please help.
All you need to do is call getActivity()
on PendingIntent
, for an Intent
that is your configuration activity, and tie that to something in the app widget via setOnClickPendingIntent()
. Here is a sample project demonstrating this.
精彩评论