Launching activity from widget

后端 未结 9 1160
深忆病人
深忆病人 2020-11-29 00:26

I\'m trying to do something which really ought to be quite easy, but it\'s driving me crazy. I\'m trying to launch an activity when a home screen widget is pressed, such as

相关标签:
9条回答
  • 2020-11-29 01:08

    I just wanted to note this here somewhere as I have been (quite stupidly) battling this all night. Basically I did all the intent code correctly but nothing would be launched.

    The problem was that I accidentally had a call like this

    super.onUpdate(context, appWidgetManager, appWidgetIds);
    

    at the end of my Overridden onUpdate() function.

    Make sure you DO NOT have this call to super as it will clear out all pending intents you've set up!

    0 讨论(0)
  • 2020-11-29 01:10

    you must define your configuration activity in res/xml/volume_changer_info.xml. Add this tag and give a fully qualified path to the configuration activity.

    android:configure = ""


    e.g.

    <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
        android:minWidth="200dip"
        android:minHeight="100dip"
        android:updatePeriodMillis="60000"
        android:initialLayout="@layout/widget_loading"
        android:configure = "org.raza.ConfigureWidgetActivity"/>
    
    0 讨论(0)
  • 2020-11-29 01:10

    I know this thread is ancient, but... Other answers describe your burnt Toast problem. As to why your pop-up activity doesn't launch on touch, you may need to enable the "update" action in order to launch and call your onUpdate() method. For that I think you need to add the "APPWIDGET_UPDATE" action like this:

    <activity android:name=".WidgetTest" android:label="@string/hello">
        <intent_filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent_filter>
    </activity>
    

    Likewise add the APPWIDGET_ENABLED and APPWIDGET_DISABLED actions if you intend to override those methods too.

    It seems to be a very unusual API that requires you to declare the overridden methods that you want called. The usual way to get your custom version of a parent is to simply override/implement them. Maybe there's a good reason for this strange pattern, but it is not a Java pattern that I've seen before. I therefore think it is likely to trip up a great deal of app widget authors. As if app widgets were not confusing enough without this mechanism.

    0 讨论(0)
提交回复
热议问题