What exactly do you mean by launching and starting an AppWidget? AppWidgets can't be launched or started... they can be updated.
On Nov 12, 2009 4:23 PM, "anand" <[email protected]> wrote: Hi all, I am trying to launch an app widget from another application. On click of a button in an application, the appwidget is receiving the message i broadcasted. I have implemented the appwidgetprovider class. In the appwidgetprovider class, in the onReceive function i am able to get the broadcasted message. My broadcast file is: package com.example.broadcast; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; public class broadcast extends Activity implements View.OnClickListener { /** Called when the activity is first created. */ public static final String ACTION_UPDATE_WIDGET = "Broadcast_Message"; public static final String MESSAGE = "message"; public void onClick(View v) { sendBroadcast(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button start = (Button) findViewById(R.id.button); start.setOnClickListener(this); } private void sendBroadcast() { Log.i("test", "send broadcast"); Intent broadcast = new Intent(this, receiver.class); broadcast.putExtra(MESSAGE, "Bye"); broadcast.setAction(ACTION_UPDATE_WIDGET); sendBroadcast(broadcast); Log.i("test", "after send"); } } My appwidget class is as follows: package com.example.broadcast; import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Toast; public class receiver extends AppWidgetProvider { public void onReceive ( Context context,Intent intent ){ //super.onReceive(context,intent ); String action = intent.getAction(); String message=""; //String packagename=""; int appwidgetid; Log.i("test", "message received"); if( "Broadcast_Message".equals ( action ) ) { //String message; Toast.makeText( context, "Broadcast sucessfull...", Toast.LENGTH_LONG).show(); if ( intent.hasExtra(broadcast.MESSAGE)) { message = (String) intent.getCharSequenceExtra(broadcast.MESSAGE); Toast.makeText( context, message, Toast.LENGTH_LONG).show(); } message = message+"in the for loop"; updateSampleWidget( context, appWidgetManager, 1,message ); } } private void updateSampleWidget(Context context,AppWidgetManager appWidgetManager, int widget, String text) { Log.i("test","In the update sample widget function"); RemoteViews views = new RemoteViews (context.getPackageName (),R.layout.widget_provider); views.setTextViewText(R.layout.widget, text); //Intent intent1 = new Intent(context, broadcast.class); //PendingIntent pendingIntent = PendingIntent.getActivity (context, 0,intent1, 0); //views.setOnClickPendingIntent(R.layout.widget, pendingIntent); //appWidgetManager.updateAppWidget(widget, views); } } The widget_provider.xml file contains the appwidget resource file. The widget.xml file contains a textview element only. The updateSampleWidget function is not getting executed. Am i doing anything wrong here??? My questions are: 1. Is it possible to start an appwidet from the onReceive function? 2. Is it possible to start an appwidget from another applicaion by sending and receiving a broadcast message? Can any one help me on this? Regards, Anand -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected]<android-beginners%[email protected]> For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

