Here is the sample code:
Class SomeClass extends Activity {
public void someMethod() {
Runnable r = new Runnable() {
public void run() {
Intent service = new Intent(SomeClass.this, SomeOtherClass.class);
// ...
}
}
}
}
How can I change the code to not use SomeClass ( in new Intent(SomeClass.this, ...))?
I want to place this sample in multiple classes and I do not want each time use different class name.
Shorter method (suggested):
Replacing
SomeClass.thisin your Intent withgetApplicationContext()should do the trick.Method I use (a little more drawn out and probably not the best of the two):
In each class, make a
private Context mContext;Then, in the
onCreate()of each class, makemContext = this;Finally, replace
SomeClass.thisin your Intent withmContext.