2012-02-07 3 views
0

매분 sdcard에서 비트 맵을 다운로드하고 화면에 인쇄 할 위젯을 만들어야합니다. 나는 시도한 바있다.비트 맵을 다운로드하여 인쇄하는 Android 위젯이 작동하지 않습니다.

private class MyTime extends TimerTask 

그러나 작동하지 않는다. . 위젯이 작동하려면 난 내 코드를 삽입 할 수있는 위젯은 내가 코드의 샘플을 필요 이것 좀 도움이 될 수 있습니다 이미지가 총 30K가 :(업데이트하지 않는 이것은 코드입니다.

를 의 TimerTask가 자신의 스레드에서 실행되기 때문에
public class MyWidget extends AppWidgetProvider { 
public int tt=0; 

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
    if(tt==0) { 
     Timer timer = new Timer(); 
     timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 10000); 
     tt=1; 
    } 
} 

private class MyTime extends TimerTask { 

    RemoteViews remoteViews; 
    AppWidgetManager appWidgetManager; 
    long t=0,lastUpdate=0; 
    ComponentName thisWidget; 

    public MyTime(Context context, AppWidgetManager appWidgetManager) { 

     this.appWidgetManager = appWidgetManager; 
     remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); 
     thisWidget = new ComponentName(context, MyWidget.class); 
    } 
    @Override 
    public void run() { 

     DateFormat dateFormat = new SimpleDateFormat("dd/MM HH:mm"); 
     //get current date time with Date() 
     Date date = new Date(); 
    remoteViews.setTextViewText(R.id.Clock,dateFormat.format(date)); 
    appWidgetManager.updateAppWidget(thisWidget, remoteViews); 

     if(t==0 || t + 100000<=System.currentTimeMillis()) { 
      checkUpdate(); 
      display(); 
      t=System.currentTimeMillis(); 
     } 
    } 
+0

'업데이트하지 않음'은 UI 변경이 없거나 오류가 발생하거나 실패 함을 의미합니다. –

+0

main.xml –

+0

에 초기 XML이 남아 있고 코드가 실행되고 UI 상태가 변경되어야합니다. –

답변

0

이 아마 실패,하지만 당신은 UI (주) 스레드가 아닌 다른 스레드에서 안드로이드 UI 라이브러리 호출을 할 수 없습니다.

하는 시간 초과 실행하려면 UI 스레드에 대한 작업, 자신에게 Handler를 할당하고 postDelayed/postAtTime 전화를 사용합니다.

관련 문제