1

I have an appwidgetprovider which updates my sqlite database when the icons are "clicked" by the user. This is triggered by the onRecieve method and has worked fine but it now appears it will only work when records have been created by the activity first.

The database is handled by its own DBadapter class and both the activity and the appwidgetprovider use this class in the same way:

mydb = new DBadapter(this);  
mydb = mydb.open();

As the DBadapter creates the database in the onCreate method I cannot understand why the activity a) creates the database and b) can create the first record but the appwidgetprovider cannot.

The only other usage that the activity does do extra to the appwidgetprovider is using a database cursor to navigate through the database.

Are there restrictions to the appwidgetprovider where it cannot actually create the database if it has not already been created by the activity? If so this would mean that the app would have to be started first after being installed and then a dummy record would have to be created/deleted because I tested this and found that once the activity created and then deleted a record , the appwidgetprovider could then write to the database.

Forgot to mention that the onReceive calls a private method to do the repetitive task of adding the record to the database. This has been the case from the start and when records already exist it works but when there are none it does not create any records

TimCS
  • 363
  • 1
  • 7
  • 17
  • Can the Android emulator cause erratic behaviour ? I have removed the code that calls the method which writes to the database and put Toast displays in the sections that call it, to start with they were not coming up, I also was in the throws of creating a second appwidgetprovider but this had not been set up in the Manifest at that point. Now I have set the second one up completely the Toast displays are working so I do not know what has happened and I need to put back the database part to see if this works now – TimCS Jan 27 '13 at 16:13
  • Hi, Perhaps find your **solution** [here](https://stackoverflow.com/questions/21130074/android-sqlite-table-not-created/44469945#44469945) – HamidReza Heydari Jun 10 '17 at 05:44

1 Answers1

0

Operator error here I posted a question and then answered that within this thread:

Appwidget question

So I then started coded the onReceive method and stupidly too out the:

} else { 

       super.onReceive(ctx,intent);
   }

Part of the code and then just left the supper.onReceive at the bottom of the method, since re-applying this it is now writing to the database. Sorry for this .

I hang my head in shame :)

Community
  • 1
  • 1
TimCS
  • 363
  • 1
  • 7
  • 17