Skip to content Skip to sidebar Skip to footer

Get Object Out Of A Method(runnable) Timer

I have implemented a timer that parses a URL every 15 min (the Timer task). An object called ParsedExampleDataSet gets that data. Whenever I try to retrieve that Object or a Strin

Solution 1:

I think it's because when you do: Context context = this.getBaseContext() inside the TimerTask() class, you are referring to a variable which is out of the scope of the class. Because TimerTask() doesn't subclass from ContextWrapper, it doesn't get the context directly. To get the context of the activity (hopefully! and not Application's context), you should do: Context context = ParsedExampleDataSet.this.getBaseContext(); That way you probably shouldn't get any null pointer exceptions.


Post a Comment for "Get Object Out Of A Method(runnable) Timer"