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 9004749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:57:58+00:00 2026-06-16T00:57:58+00:00

Code is written down to update the widget. this code works always Toast.makeText(context, +cd.getId(),

  • 0

Code is written down to update the widget.

this code works always

Toast.makeText(context, ""+cd.getId(), Toast.LENGTH_LONG).show();

But nether code only works when it is Debug.

@Override
public void onUpdate(Context context, AppWidgetManager appwidgetmanager,
        int[] appWidgetIds) {

    for (int i : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(),
                R.layout.widget4x4persian);
        shaffle(context, appwidgetmanager, i, views);
    }

}

@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;
    super.onReceive(context, intent);
    ComponentName thisWidget = new ComponentName(context, gift4x4.class);
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
            R.layout.widget4x4persian);
    AppWidgetManager appWidgetManager = AppWidgetManager
            .getInstance(context);
    appWidgetManager.updateAppWidget(thisWidget, remoteViews);
    clickWidget(context, appWidgetManager, intent, remoteViews);
}

private void clickWidget(Context context,
        AppWidgetManager appWidgetManager, Intent intent,
        RemoteViews remoteViews) {

    Cursor c = null;
    try {

        ComponentName thisWidget = new ComponentName(context, gift4x4.class);

        Bundle b = intent.getExtras();

        if (b != null) {
            int key = b.getInt(WIDGET_KEY);

            String id = null;

                int[] allWidgetIds = appWidgetManager
                        .getAppWidgetIds(thisWidget);
                for (int i : allWidgetIds) {
                    RemoteViews views = new RemoteViews(
                            context.getPackageName(),
                            R.layout.widget4x4persian);
                    shaffle(context, appWidgetManager, i, remoteViews);
                }
            }

    } catch (NumberFormatException e) {
        e.getMessage();
    } finally {
        if (c != null)
            c.close();
    }
}

public void shaffle(Context context, AppWidgetManager appwidgetmanager,
        int appWidgetId, RemoteViews Rview) {
    Cursor c = null;
    try {

        Card cd = null;
        do {
            PreferenceManager pm = new PreferenceManager(context);
            Cards_Count = pm.get(PREFNAME_CARDS_COUNTS, CARDS_COUNTS);
            int shaffle = (new Random()).nextInt(Cards_Count);

            c = context.getContentResolver().query(CONTENT_URI_CARDS,
                    new String[] { ID, TEXT, ISREAD, ISBOOKMARK, NOTE },
                    "id=" + shaffle, null, null);
            if (c.moveToFirst()) {
                cd = new Card(c.getInt(c.getColumnIndex(ID)), c.getString(c
                        .getColumnIndex(TEXT)), c.getInt(c
                        .getColumnIndex(ISREAD)), c.getInt(c
                        .getColumnIndex(ISBOOKMARK)), c.getString(c
                        .getColumnIndex(NOTE)));
            }
            c.close();
        } while (c == null);

        Rview.setImageViewResource(R.id.imgIsBookmarkWidget, cd
                .getIsBookmark() == 1 ? R.drawable.bookmark
                : R.drawable.unbookmark);

        Bitmap bmp = getPicture(context, cd.getId());
                    Toast.makeText(context, ""+cd.getId(), Toast.LENGTH_LONG).show();
        Rview.setImageViewBitmap(R.id.imgWidget, bmp);
        Intent  intentTemp = new Intent(context, gift4x4.class);
        intentTemp.putExtra(WIDGET_KEY, key);

        PendingIntent   pendingintentTemp = PendingIntent.getBroadcast(context, key,
                intentTemp, PendingIntent.FLAG_UPDATE_CURRENT);

        Rview.setOnClickPendingIntent(R.id.imgShaffleWidget,
                getProperIntent(context, 3, cd));


        appwidgetmanager.updateAppWidget(appWidgetId, Rview);

    } catch (Exception e) {
        e.getMessage();
    } finally {
        if (c != null)
            c.close();
    }
}
  • 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-16T00:58:00+00:00Added an answer on June 16, 2026 at 12:58 am

    Maybe the Context you are using is not the right type.
    Just use the context which is passed into function, don’t use private contexts declared in class.

    public void onReceive(Context context, Intent intent)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code for displaying a drop down list, but the code
I have written a cascading drop down list using JQuery. The code that I
I have following code written to run NSTimer . But the NSTimer selector is
I've sometimes seen code written like this : public class B1 { } public
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I'm approaching pthreads library in C, I have written down some dummy code in
I've been vectorizing some matlab code I'd previously written, and during this process matlab
I am working on some code written by a co-worker who no longer works
I'm often having code written as follows try: self.title = item.title().content.string except AttributeError, e:
I have code written in c, which contains some complex algorithms and I want

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.