Я пытаюсь обновить свой пользовательский интерфейс в FirstActivity
, когда получаю уведомление, но меня сбивает с толку runOnUiThread
, Запускаемый
и Обработчик
. Вот что у меня есть: я использую FirstActivity и NotificationService. Когда NotificationService получает уведомление, он обновляет интерфейс FirstActivity.
У меня также работает другая служба AlarmService
.
Первое действие
@Override
public void onResume() {
super.onResume();
//some other code for alarm service
}
NotificationService
//on receiving notification
private void showNotification(String text) {
//Get activity
Class<?> activityClass = null;
try {
activityClass = Class.forName("com.pakage.FirstActivity");
contextActivity = (Activity) activityClass.newInstance();
//Update UI on FirstActivity not working
contextActivity.runOnUiThread(new Runnable() {
public void run()
{
Looper.prepare();
TextView tv = (TextView ) contextActivity.findViewById(R.id.notifyTest);
Looper.loop();
}
});
} catch (Exception e) {
e.printStackTrace();
}
//Shows the notification
Notification n = new Notification();
//... etc
}
Я все время получаю ошибку looper.prepare. Нужно ли мне добавлять дополнительные коды в свой FirstActivity?