Android widget works well in emulator but on phone it turns into the Google App widget -
i created android widget.
in genymotion nexus 4 emulator running android 4.4.4 works well.
on nexus 4 device running android 4.4.4 put widget on home screen , turns google app widget.
turns widget again google app widget , on. until remove widget home screen.
using parse.com online storage , on phone data doesn't seem obtained. can't tell sure because widget keeps changing.
widget contains 3 files.
1 extends application class:
public class myapp extends application { private mymodel model; @override public void oncreate() { parse.enablelocaldatastore(this); parseobject.registersubclass(gdbddata.class); parse.initialize(this, "-", "-"); if(model == null) { intent intent = new intent(this,gdbdwidgetprovider.class); intent.setaction(widgetutils.widget_refresh_storage); intent.putextra("userid",123); sendbroadcast(intent); } super.oncreate(); }
one widgetprovider:
@override public void onreceive(context context, intent intent) { super.onreceive(context, intent); final string action = intent.getaction(); if (action.equals(widgetutils.widget_refresh_storage)) { myapp app = ((myapp)context.getapplicationcontext()); int userid = intent.getintextra("userid",0); trygetmodelfromremotestorage(userid,context); } } static void updateappwidget(context context, appwidgetmanager appwidgetmanager, int appwidgetid) { myapp app = ((myapp)context.getapplicationcontext()); mymodel model = app.getmodel(); // construct remoteviews object remoteviews remoteviews = new remoteviews(context.getpackagename(), r.layout.the_widget); pendingintent clickerpendingintent = buildbuttonpendingintent(context); // change textviews , imageviews inside widget here appwidgetmanager.updateappwidget(appwidgetid, remoteviews); } public static pendingintent buildbuttonpendingintent(context context) { // initiate widget update request intent intent = new intent(); intent.setaction(widgetutils.widget_update_action); pendingintent pendingintent = pendingintent.getbroadcast(context, 0, intent, 0); return pendingintent; }
and 1 broadcastreceiver handles button on widget:
@override public void onreceive(context context, intent intent) { if (intent.getaction().equals(widgetutils.widget_update_action)) { updatewidget(context); } } private void updatewidget(context context) { myapp app = ((myapp)context.getapplicationcontext()); mymodel model = app.getmodel(); //i update fields in model based on business rules @ point mywidgetprovider.sendupdatemessagetowidgets(context); }
does know doing wrong?
edit 1: adding manifest file requested
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.app.main" > <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <application android:name="myapp" android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <receiver android:name=".gdbdwidgetprovider" > <intent-filter> <action android:name="android.appwidget.action.appwidget_enabled" /> <action android:name="android.appwidget.action.appwidget_update" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/the_widget_info" /> </receiver> <receiver android:name=".tapmarkdayintentreceiver" android:label="@string/app_name" > <intent-filter> <action android:name="com.my.app.intents.update_widget" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/the_widget_info" /> </receiver> </application> </manifest>
edit 2, added widget xml file:
<?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minwidth="140dp" android:minheight="140dp" android:updateperiodmillis="1000000" android:previewimage="@drawable/example_appwidget_preview" android:initiallayout="@layout/the_widget" android:widgetcategory="home_screen" android:initialkeyguardlayout="@layout/the_widget"></appwidget-provider>
sorry not answering last comments busy.
thank help.
happened had return statements in widgetprovider's onupdate, onenabled, ondisabled , orreceive methods , apparently bad thing. once removed them no longer occured.
Comments
Post a Comment