Sunday, June 12, 2011

Re: [android-developers] can't launch activity from my appwidget

David,
 
In the code you posted, I don't see a call to appWidgetManager.updateAppWidget with the remoteViews object you're building. RemoteViews is not at all like an RPC connection where you do stuff "on one side", in your code, and it magically appears "on the other side", in the widget. You need to call updateAppWidget at some point, so that whatever operations you built up in the RemoteViews is actually pushed to your widget.
 
Point two - it's not clear to me what is the relation of this code to the service called Servicio. If the service also pushes a RemoteViews update, it's going to overwrite the update with the pending intent, causing it to be lost.
 
All your RemoteViews operations should go into one object instance, which should be "complete" and contain: calls to setTextViewText / setImageViewResource / etc. to show data, as well as pending intents.
 
Finally, this comes up pretty often, you might want to search the group for past discussions.
 
-- Kostya

2011/6/12 ABSOLUT <davidtuti@gmail.com>
Hi,

I have a button in my appwidget that I would like that launch the
activity. I have this in the code:

 public void onUpdate(Context context, AppWidgetManager
appWidgetManager,
           int[] appWidgetIds) {

RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
Intent intent = new Intent(context.getApplicationContext(),
Servicio.class);
       context.startService(intent);
       Intent intent2 = new Intent(context.getApplicationContext(),
tele.class);
       PendingIntent pendingIntent =
PendingIntent.getActivity(context.getApplicationContext(), 0, intent2,
intent2.FLAG_ACTIVITY_NEW_TASK);
       remoteViews.setOnClickPendingIntent(R.id.textoWidgetCron,
pendingIntent);

But the activity doesn't start. Could you help me please?
Thanks and sorry for my english!


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment