English 中文(简体)
Android:更新更多植被
原标题:Android : Alarm for update more widget

我使用AlarmManager,每二次更新一次植被,但当增加更多的植被时,只更新了最后的植被。 我没有说明为什么......

这是法典......

public class widget extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
        SharedPreferences preference = context.getSharedPreferences("MY_PREFERENCE", Context.MODE_PRIVATE);
        Intent intent = new Intent(context,vampireServiceWidget.class);
        context.startService(intent);
        for(int i=0; i<appWidgetIds.length;i++){        
            if(preference.getLong("countdown", 0)!=0){
                //Parte il countdown
                Intent in = new Intent().setAction("it.android.dev.thevampirediaries.UPDATE_COUNTDOWN");
                in.putExtra("id_widget", appWidgetIds[i]);
                in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent pi = PendingIntent.getBroadcast(context, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
                AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
                alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 1000, pi); 

                    }       }

}

- 《刑法》

    AppWidgetManager manager = AppWidgetManager.getInstance(context);
            RemoteViews remoteView = new RemoteViews(context.getPackageName(),R.layout.widgett);
         thisWidget=intent.getIntExtra("id_widget", 0)
            SimpleTimeFormat tf = new SimpleTimeFormat("$dd$ : $HH$: $mm$: $ss$");    
            String risultato = tf.format(countdown_data_fine - new Date().getTime()); // arg0 tempo
            remoteView.setTextViewText(R.id.textView1, titolo_puntata);
            remoteView.setTextViewText(R.id.textView2, risultato);
            manager.updateAppWidget(thisWidget, remoteView);
最佳回答

评论 lo,不寄出植被。 Use .

引言

public class widget extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
        SharedPreferences preference = context.getSharedPreferences("MY_PREFERENCE", Context.MODE_PRIVATE);
        Intent intent = new Intent(context,vampireServiceWidget.class);
        context.startService(intent);
        //for(int i=0; i<appWidgetIds.length;i++){        
            if(preference.getLong("countdown", 0)!=0){
                //Parte il countdown
                Intent in = new   Intent().setAction("it.android.dev.thevampirediaries.UPDATE_COUNTDOWN");
                in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent pi = PendingIntent.getBroadcast(context, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
                AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
                alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 1000, pi); 

             }     
       }

iii

================================================================================================================================================================================================================================================================

    AppWidgetManager manager = AppWidgetManager.getInstance(context);
                RemoteViews remoteView = new RemoteViews(context.getPackageName(),R.layout.widgett);
ComponentName thisWidget = new ComponentName(context, widget.class);
    SimpleTimeFormat tf = new SimpleTimeFormat("$dd$ : $HH$: $mm$: $ss$");    
                String risultato = tf.format(countdown_data_fine - new Date().getTime());
                remoteView.setTextViewText(R.id.textView1, titolo_puntata);
                remoteView.setTextViewText(R.id.textView2, risultato);
                manager.updateAppWidget(thisWidget, remoteView);
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签