hamedata
hamedata

Reputation: 125

run startService in static method

i have this function as static method:

    public static void engine(SQLiteDatabase mydb){
        Intent intent = new Intent(context, GPSLocation.class);
        intent.putExtra("sql_obj", mydb); 
        startService(intent);
    }

but startService return follow error:

Cannot make a static reference to the non-static method startService(Intent) from the type ContextWrapper

is there any way to startService in static method?

Upvotes: 2

Views: 1977

Answers (1)

nikis
nikis

Reputation: 11234

Looks like you've already got a reference to a Context class via context variable (since you are using it to create intent Intent intent = new Intent(context, GPSLocation.class);), so you can start it from the static context in the following way:

context.startService(intent)

Upvotes: 3

Related Questions