как вызвать обработчик класса фрагмента из класса широковещательного приемника для обновления основного потока? - PullRequest
0 голосов
/ 26 мая 2020

Я хочу обновить поток myfragment, вызвав myfunction, которая реализует обработчик. Но я не знаю, как получить доступ к этому обработчику из класса широковещательного приемника. Может ли кто-нибудь мне в этом помочь?

Код класса фрагмента:

    Calendar calendar= Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY,16);
    calendar.set(Calendar.MINUTE,42);
    calendar.set(Calendar.SECOND,0);
    Intent intent =new Intent(getContext(),NotificationActivity.class);
    intent.putExtra("id",R.id.notification_imageView);
    PendingIntent pendingIntent =  
    PendingIntent.getBroadcast(getContext(),100,intent,PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager=(AlarmManager) getActivity().getSystemService(ALARM_SERVICE);
    System.out.println("DEBUG==> Instantiating Alarm Manager Service");
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),1000 * 60 * 
    02,pendingIntent);

Реализация обработчика обновления пользовательского интерфейса (в классе фрагмента)

       public void myfunction()
       {
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ImageView img;

                View view = View.inflate(context, R.layout.Sample, null);
                img = view.findViewById(R.id.imageView);


                Animation animation = new AlphaAnimation((float) 0.5, 0); 
                animation.setDuration(500); // duration - half a second--2 minutes
                animation.setRepeatCount(200);
                img.startAnimation(animation);

                handler.postDelayed(this, 100000);
            }
            }, 100000);
           }

Класс BroadcastReceiever --ClassNotificationActivity.class

  public class NotificationActivity extends BroadcastReceiver {
  private View view;
  @Override
   public void onReceive(Context context, Intent intent) {
   ///How to call handler myfunction from here
      }
         }

Manifest. xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SET_ALARM" />

 <receiver  android:name=".view.ui.NotificationActivity" />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...