Reputation: 3031
I have a class which extend Intent service. I want to start service from this activity but I get erroor:
Intent msgIntent = new Intent();
msgIntent.setClass(testActivity, testActivity.class);
startService(msgIntent);
07-15 11:53:33.030: E/AndroidRuntime(28989): java.lang.NullPointerException
07-15 11:53:33.030: E/AndroidRuntime(28989): at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
How can I start service from the same activity?
Upvotes: 0
Views: 79
Reputation: 380
it looks like you are calling startService with testActivity, which is an activity, not a service.
try like that:
Intent msgIntent = new Intent(this, yourIntentService.class);
startService(msgIntent);
Upvotes: 0
Reputation: 21117
Intent msgIntent = new Intent(YourClass.this, TestService.class);
startService(msgIntent);
Upvotes: 2