Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3302458
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:51:14+00:00 2026-05-17T20:51:14+00:00

the document http://developer.android.com/guide/topics/data/data-storage.html shows that there are multiple ways to save data, I need

  • 0

the document
http://developer.android.com/guide/topics/data/data-storage.html

shows that there are multiple ways to save data, I need to do this in a widget and everytime I try to save i get errors…

for instance

      SharedPreferences settings = getSharedPreferences("NAME", 0);
      SharedPreferences.Editor editor = settings.edit();
      editor.putBoolean("silentMode", false);

      // Commit the edits!
      editor.commit();

Error

Description Resource    Path    Location    Type
The method getSharedPreferences(String, int) is undefined for the type AWidget

another attempt:

     String FILENAME = "hello_file";
     String string = "hello world!";

     FileOutputStream fos = openFileOutput("Test.txt", Context.MODE_PRIVATE);
     fos.write(string.getBytes());
     fos.close();

with error

Description Resource    Path    Location    Type
The method openFileOutput(String, int) is undefined for the type AWidget

whats the deal? I see no mention this does not work in a widget so why is it that these examples don’t work for me?

What is the preferred way to save this data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:51:14+00:00Added an answer on May 17, 2026 at 8:51 pm

    So the issue is is that I cannot just use this function without substance the above code will work fine if I do it with context. in front of it…

     SharedPreferences settings = context.getSharedPreferences("NAME", 0);
          SharedPreferences.Editor editor = settings.edit();
          editor.putBoolean("silentMode", false);
    
          // Commit the edits!
          editor.commit();
    

    So as you can see that is all that was need to get the shared preferences… and with this…

    int[] allids = AppWidgetManager
    .getInstance(context)
    .getAppWidgetIds(new ComponentName(context, AwarenessWidget.class));

    I can get all the IDs of my app and call onupdate and update each ones views based upon the saved preferences

    I can elaborate more if anyone needs…

    Baffels me no one was able to figure that one out and help me! seems very straight forward now!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.