I am trying to update my user interface in FirstActivitywhen I receive a notification, but it is confused runOnUiThread, Runnableand Handler. Here is what I have: I run FirstActivity and NotificationService. When the NotificationService re-receives the notification, it will update the FirstActivity interface.
I also have another service AlarmService. First activity
@Override
public void onResume() {
super.onResume();
}
NotificationService
private void showNotification(String text) {
Class<?> activityClass = null;
try {
activityClass = Class.forName("com.pakage.FirstActivity");
contextActivity = (Activity) activityClass.newInstance();
contextActivity.runOnUiThread(new Runnable() {
public void run()
{
Looper.prepare();
TextView tv = (TextView ) contextActivity.findViewById(R.id.notifyTest);
Looper.loop();
}
});
} catch (Exception e) {
e.printStackTrace();
}
Notification n = new Notification();
}
I get looper.prepare error. Do I need to enter additional codes in my FirstActivity?
source
share