I'm on a activity with a textview and in the background is AlarmReceiver running with a 10min time trigger. The activity has a method which I want to call by the trigger. The method sets a new value to the textview. But by calling it from the trigger I can not use "findViewById". I get a NullPointerException at this point. I also tried to setContentView when its called by the trigger but also here I get an NullPointerException
This it the Code:
ValuesActivity:
public void setSyncValue(Context context, boolean fromSyncService, String value){
try {
if(fromSyncService){
setContentView(R.layout.activity_values);
}
...
try{
...
TextView lastSyncTV = (TextView) findViewById(R.id.last_sync_label);
lastSyncTV.setText(value);
...
} catch (Exception ex) {
....
}
} catch (Exception ex) {
....
}
}
AlarmReceiver
@Override
public void onReceive(Context context, Intent intent) {
try {
Intent i = new Intent(context, SyncService.class);
context.startService(i);
}catch (Exception ex){
.....
}
}
SyncService
//runns every 10min
@Override
protected void onHandleIntent(Intent intent) {
try {
...
ValuesActivity valuesActivity = new ValuesActivity();
valuesActivity.setSyncValue(....)
....
}
.....
}