Please do not update an app widget every second. If you want to update something on the home screen every second, write your own home screen.
Beyond that, a manifest-registered BroadcastReceiver (like your AppWidgetProvider) cannot use Timer, as that forks a background thread, and a manifest-registered BroadcastReceiver cannot safely do things that will last beyond the end of onReceive(). On Tue, Sep 27, 2011 at 1:35 AM, Himanshu Mistri <[email protected]> wrote: > Hello, > Every One in this google Can any one guide me what i suppose to do wrong in > update the image view of android widget in every one second what can i do > for that , > Here is code that i use but get error can one solve this ... > > public class HelloWidget extends AppWidgetProvider{ > Context mContext; > public static final int UPDATE_RATE = 1000; > //public Integer[] mThumbIds = {R.drawable.arrow_s}; > @Override > public void onReceive(Context context, Intent intent) { > super.onReceive(context, intent); > } > @Override > public void onUpdate(Context context, AppWidgetManager appWidgetManager, > int[] appWidgetIds) { > this.mContext=context; > Timer timer=new Timer(); > timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000); > // for (int appWidgetId : appWidgetIds) { > // setAlarm(context, appWidgetId, UPDATE_RATE); > // } > } > Bitmap mBitmap2; > ImageView mImageView; > private class MyTime extends TimerTask{ > RemoteViews mRemoteViews; > AppWidgetManager mAppWidgetManager; > ComponentName mComponentName; > DateFormat format=SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, > Locale.getDefault()); > public MyTime(Context context,AppWidgetManager appWidgetManager){ > this.mAppWidgetManager=appWidgetManager; > mRemoteViews=new RemoteViews(context.getPackageName(), R.layout.main); > mComponentName=new ComponentName(context, HelloWidget.class); > } > @Override > public void run() { > // mBitmap=Bitmap.createBitmap(mBitmap2); > // mImageView=new ImageView(mContext); > //mImageView.setImageResource(mThumbIds[0]); > // mImageView.setImageBitmap(mBitmap2); > mBitmap2=Bitmap.createBitmap(10, 146, Bitmap.Config.ARGB_8888); > mBitmap2=BitmapFactory.decodeResource(mContext.getResources(),R.id.secondhand); > Matrix mat=new Matrix(); > mat.postRotate(6, 0.5f, 0.5f); > Bitmap rotate=Bitmap.createBitmap(mBitmap2, 0, 0, mBitmap2.getWidth(), > mBitmap2.getHeight(), mat, true); > I try this but this also not work > // Date dt = new Date(); > // int seconds = dt.getSeconds(); > // Log.v("log_tag", "seconds" + seconds); > // RotateAnimation rotateAnimation = new RotateAnimation( > // (seconds - 1) * 6, seconds * 6, > // Animation.RELATIVE_TO_SELF, 0.5f, > // Animation.RELATIVE_TO_SELF, 0.5f); > // > // rotateAnimation.setInterpolator(new LinearInterpolator()); > // rotateAnimation.setDuration(1000); > // rotateAnimation.setFillAfter(true); > // mImageView.setAnimation(rotateAnimation); > // mBitmap=mImageView.getDrawingCache(); > > //mRemoteViews.describeContents(); > //mRemoteViews.setImageViewResource(R.id.secondhand, R.id.secondextra); > //mRemoteViews.setBitmap(R.id.secondhand, "setImageBitmap",mBitmap2 ); > mRemoteViews.setImageViewBitmap(R.id.secondhand, rotate); > // mRemoteViews.setImageViewResource(R.id.secondhand, > R.drawable.widgetdial); > mRemoteViews.setTextViewText(R.id.widget_text, "Time:-"+format.format(new > Date())); > mAppWidgetManager.updateAppWidget(mComponentName,mRemoteViews); > } > } > } > Thanks in Advance for any reply. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 2.0 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

