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

  • Home
  • SEARCH
  • 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 8027499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:49:57+00:00 2026-06-04T23:49:57+00:00

I am trying to make a simple toggle button in an appwidget. to do

  • 0

I am trying to make a simple toggle button in an appwidget.
to do that i want to save the current state and i am using the shared prefs for that ..
and yet i still have trouble.

The value of the boolean isRecordting is alwasy false

here is the on recive:

@Override
    public void onReceive(Context context, Intent intent)
    {
        switchToggle(context, intent);

        super.onReceive(context, intent);
    }

    private void switchToggle(Context context, Intent intent)
    {
        SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE);
        isRecording = prefs.getBoolean(IS_RECORDING, false);
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget);
        Log.d(TAG,"Toggle State: " + isRecording);

        if (isRecording)
        {
            remoteViews.setImageViewResource(R.id.btnRecordToggle, R.drawable.record_button_enabled);
        }
        else
        {
            remoteViews.setImageViewResource(R.id.btnRecordToggle, R.drawable.record_button);
        }

        ComponentName componentName = new ComponentName(context, RecorderWidget.class); 
        AppWidgetManager.getInstance(context).updateAppWidget(componentName, remoteViews);
        isRecording = !isRecording;
        prefs.edit().putBoolean(IS_RECORDING, isRecording);
    }

Here is the On Update:

@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
    {
        // TODO Auto-generated method stub
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        for (int widgetId : appWidgetIds) 
        {
            RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget);

            // Register an onClickListener
            Intent intent = new Intent(context, RecorderWidget.class);
            intent.setAction(ACTION_START_RECORDING);

            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            remoteViews.setOnClickPendingIntent(R.id.btnRecordToggle, pendingIntent);


            appWidgetManager.updateAppWidget(widgetId, remoteViews);
        }
  • 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-06-04T23:49:59+00:00Added an answer on June 4, 2026 at 11:49 pm

    Found the problem !!!..

    i needed to commit the chages to my shearde prefs ..
    sorry to boder ya all …

    here is the fixed code:

        private void switchToggle(Context context, Intent intent)
            {
                SharedPreferences prefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE);
                isRecording = prefs.getBoolean(IS_RECORDING, false);
                RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget);
                Log.d(TAG,"Toggle State: " + isRecording);
    
                if (isRecording)
                {
                    remoteViews.setImageViewResource(R.id.btnRecordToggle, R.drawable.record_button_enabled);
                }
                else
                {
                    remoteViews.setImageViewResource(R.id.btnRecordToggle, R.drawable.record_button);
                }
    
                ComponentName componentName = new ComponentName(context, LifeRecorderWidget.class); 
                AppWidgetManager.getInstance(context).updateAppWidget(componentName, remoteViews);
                isRecording = !isRecording;
    
               //THIS IS THE FIX
                SharedPreferences.Editor editor = prefs.edit();
                editor.putBoolean(IS_RECORDING, isRecording);
                editor.commit();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a simple client that consumes a web service using RemObjects SDK,
I am trying to make a simple toggle button in javascript. However, the button
Trying to make simple jQuery function to create a scrollToTop button that fades in
I'm trying to make a simple link that will toggle my status attribute in
I'm trying to make a very simple toggle switch and I want to store
Trying to make a simple scroll to top button that smoothly scrolls up and
I'm trying to make simple script using jquery $post function to pass data to
I'm trying to make a simple video chat using Flex framework and red5 server.
im currently trying to make a simple IRC Gui Client. Im using the SmartIrc4net
Trying to make a simple toggle menu, and I can't seem to hide/show the

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.