getApplicationContext() returns null in a Service
10,929
You are running your Service
in a different process so it has no communication with the Actual Application process..
Try to remove this line from your service
android:process=":pointservice"
After your application is finished Application context is becomes null. At most situations there is no need to run the service in a different process. Also it is not recommended.
For more information check here
![whizzzkey](https://i.stack.imgur.com/K5R5O.jpg?s=256&g=1)
Author by
whizzzkey
Updated on July 20, 2022Comments
-
whizzzkey almost 2 years
I have a Service in it's own process, I've declared it in manifest like that:
<service android:name="com.discountscatcher.util.PointService" android:configChanges="orientation" android:process=":pointservice" > </service>
But
onStartCommand
I was trying to get anApplicationContext
, but it always returns null, what I can forget?public int onStartCommand(Intent intent, int flags, int startId) { android.os.Debug.waitForDebugger(); Context mContext = getApplicationContext(); return Service.START_STICKY; }
and I starting it like that:
startService(new Intent(getApplicationContext(), PointService.class));
in
Myactivity OnCreate
any ideas?
-
whizzzkey over 10 yearsPlease tell me for what reasons i should start a service in another process?