Unable to launch an activity from an AppWidget

by Karl Smith » Fri, 20 May 2011 09:53:37 GMT


Sponsored Links
 I have this code setup in my app widget and I have listed the activity
it should launch below. I can't for the life of me get the activity to
launch when the button is clicked. Nothing happens when I click on it.


public class MyAppWidget extends AppWidgetProvider
{
        public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds)
        {
        RemoteViews remoteViews = new
RemoteViews(context.getPackageName(), R.layout.main);


    Intent intent = new Intent(context, EditActivity.class);
                PendingIntent pendingIntent =
PendingIntent.getActivity(context, 0, intent,
Intent.FLAG_ACTIVITY_NEW_TASK);
 
remoteViews.setOnClickPendingIntent(R.id.btnEditConfiguration,
pendingIntent);

                appWidgetManager.updateAppWidget(thisWidget,
remoteViews);
            }
}

 public class EditActivity extends Activity
    {
         public void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
 
setContentView(R.layout.configure);
            }
    }

-- 



Unable to launch an activity from an AppWidget

by Karl Smith » Fri, 20 May 2011 09:53:38 GMT


 I have this code setup in my app widget and I have listed the activity
it should launch below. I can't for the life of me get the activity to
launch when the button is clicked. Nothing happens when I click on it.


public class MyAppWidget extends AppWidgetProvider
{
        public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds)
        {
public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds)
    {
        RemoteViews remoteViews = new
RemoteViews(context.getPackageName(), R.layout.main);


    Intent intent = new Intent(context, EditActivity.class);
                PendingIntent pendingIntent =
PendingIntent.getActivity(context, 0, intent,
Intent.FLAG_ACTIVITY_NEW_TASK);
 
remoteViews.setOnClickPendingIntent(R.id.btnEditConfiguration,
pendingIntent);

                appWidgetManager.updateAppWidget(thisWidget,
remoteViews);
            }
}

 public class EditActivity extends Activity
    {
         public void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
 
setContentView(R.layout.configure);
            }
    }

-- 


Sponsored Links


Re: Unable to launch an activity from an AppWidget

by Nikolay Elenkov » Fri, 20 May 2011 10:04:06 GMT


 


Are you updating the right widget?
Is btnEditConfiguration visible/enabled?
Does the Activity work when started from launcher?
Any suspicious messages in logcat?

-- 



Other Threads

1. Running new provider in Open source Framework.

I have added new provider under com.android.provider.contacts. I was
able to compile the code by  adding my Provider name to the Android.mk
file.

These are stpes are i am following.

1. .build/envsetup.sh

2. lunch 1

3. make

4. emualtor

When emulator  tries to publish my provider it's throwing below
exception. Do i need to copy any class files to Dalvikvm? Please
suggest me

 D/AndroidRuntime(  647): Shutting down VM
W/dalvikvm(  647): threadid=3: thread exiting with uncaught exception
(group=0x4000fe70)
E/AndroidRuntime(  647): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(  647): java.lang.RuntimeException: Unable to get
provider com.android.providers.contacts.CMContactsProvider:
java.lang.ClassNotFoundException:
com.android.providers.contacts.CMContactsProvider in loader
dalvik.system.pathclassloa...@435da488
E/AndroidRuntime(  647):        at android.app.ActivityThread.installProvider
(ActivityThread.java:3857)
E/AndroidRuntime(  647):        at
android.app.ActivityThread.installContentProviders(ActivityThread.java:
3659)
E/AndroidRuntime(  647):        at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:
3618)
E/AndroidRuntime(  647):        at android.app.ActivityThread.access$2500
(ActivityThread.java:112)
E/AndroidRuntime(  647):        at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1729)
E/AndroidRuntime(  647):        at android.os.Handler.dispatchMessage
(Handler.java:99)
E/AndroidRuntime(  647):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  647):        at android.app.ActivityThread.main
(ActivityThread.java:3948)
E/AndroidRuntime(  647):        at java.lang.reflect.Method.invokeNative
(Native Method)
E/AndroidRuntime(  647):        at java.lang.reflect.Method.invoke
(Method.java:521)
E/AndroidRuntime(  647):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime(  647):        at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:540)
E/AndroidRuntime(  647):        at dalvik.system.NativeStart.main(Native
Method)

--~--~---------~--~----~------------~-------~--~----~

2. As application developers are we allowed to access system properties like ro.config.sync?

Well, that's not the kind of setting that you should change in the
user's back. Launching an activity allows the user to make a conscious
decision about the way they manage their phone.

JBQ








-- 
Jean-Baptiste M. "JBQ" Queru
Android Engineer, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

--~--~---------~--~----~------------~-------~--~----~

3. How to make a video of the emulator ?

4. application stop unexpectedly

5. Developer Ethics

6. Playing .wav files on Android G1

7. BT icon on the device