I've created this code based on work I have done in activities and from other questions here on SO. I get no errors. Just a warning message:
04-30 19:19:26.063: W/BroadcastQueue(480):
Unable to launch app com.test.application/10091
for broadcast Intent { act=android.appwidget.action.APPWIDGET_ENABLED flg=0x10
cmp=com.test.application/.TestWidget }: process is bad
Followed by this to do with the update action:
04-30 19:19:26.063: W/BroadcastQueue(480): Unable to launch app
com.test.application/10091 for broadcast Intent {
act=android.appwidget.action.APPWIDGET_UPDATE flg=0x10
cmp=com.test.application/.TestWidget (has extras) }: process is bad
and then (I don't know if this is part of it, it shows up in blue):
04-30 19:19:34.073: D/Launcher.Model(752): DbDebug
Add item (null) to db, id: 126 (-100, 1, 1, 3)
Here is my code from the class TestWidget:
package com.test.application;
public class TestWidget extends AppWidgetProvider {
static DBHelper dbhelper;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
updateWidgetContent(context, appWidgetManager, appWidgetIds);
}
public static void updateWidgetContent(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
dbhelper.openDatabase();
String name = "basestring";
Cursor c = getDatabaseHelper(context).getReadableDatabase().rawQuery("SELECT * FROM websites ORDER BY RANDOM()", null);
name = c.getString(c.getColumnIndex("weburl"));
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.main);
remoteView.setTextViewText(R.id.TextView1, name);
dbhelper.close();
appWidgetManager.updateAppWidget(appWidgetIds, remoteView);
}
private static DBHelper getDatabaseHelper(Context context) {
DBHelper dbhelper = null;
if (dbhelper == null) {
dbhelper = new DBHelper(context);
dbhelper.openDatabase();
}
return dbhelper;
}
}
I took code from my experiance with database and Activities and some from here: Android: get Widget Data from database
I've never worked with pulling data from a database for widgets. Either way I'm not getting any direct errors, the widget can be placed, it's just empty where the textview should be filled.
The database I'm using has over 2000 items so it's definitely not null. I want it to just show one. I've done this perfectly in an Activity with a button. (Press the button and one result from the db shows up in a textview).
I would really love some help. I feel like I'm very close.
EDIT: I plan on making this open source when I get get it working, I can't see any other open source projects out there that help with this sort of stuff so if I get it working I can share it with everyone.