edi233
edi233

Reputation: 3031

Start service from the same activity in android

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

Answers (2)

Taldroid
Taldroid

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

Muhammad Aamir Ali
Muhammad Aamir Ali

Reputation: 21117

Intent msgIntent = new Intent(YourClass.this, TestService.class);
startService(msgIntent);

Upvotes: 2

Related Questions