• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to set a bitmap as widget

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am trying to set a piechart as a widget but i only get blank widget with default message "Tap to open this app so your widget can refresh"

the code i am using is


Never made a widget before my manifest is correct and i dont get any errors in logcat any help would be great thanks
 
Saloon Keeper
Posts: 7631
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks really weird. No Activity is involved in a widget, but you need a class extending AppWidgetProvider. That's where the onUpdate method goes.

In general, if you want to check which code of yours is called, add a Log.d(...) statement at appropriate places, e.g. between lines 4 and 5 here.

If you want to learn widgets, don't start from scratch creating one - it's not obvious what all you need to do. Start with a working one like https://www.vogella.com/tutorials/AndroidWidgets/article.html, and work your way from there.
 
john bean
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for reply i am extending correct class i think it may be due to the info being got in mainactivity and then requesting it from AppWidgetProvider class when app is closed but it should get info when app is launched but the widget stays empty just t be sure my xml is


manifest has


and xml/example_appwidget_info



A I JUST TRIED ON EMULATOR AND GOT A NULLPOINTER it seems my widgetPie which is a piechart setup in mainactivity must need to move things around

 
Tim Moores
Saloon Keeper
Posts: 7631
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the excerpts you posted I can't tell if you're going about this the right way. But "MainActivity" sounds like it might be an Activity, which is something you would never construct yourself. If it is is not an Activity, then it is not possible to advise what to check because we haven't seen enough of the code.
 
john bean
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k so i think i could not use an image from mainactivity due to the app being closed and could not gather info from onupdate in widget class so i figure save as sharedpreferences now i dont get any null pointers and it seems to be saving and loading the string but the widget is just blank if anyone can tell me what im doing wrong



this is my output



so it seems the image is saved as string and loaded but its just blank in my widget
 
john bean
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k just builth a test app and converting the layout into imageview seems to be where its going wrong



pierel is a relativelayout
 
Your mind is under my control .... your will is now mine .... read this tiny ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic