Rohit Bajaj
asked on
NullPointerException in onHandleIntent android
HI,
I am getting the following exception :
I found something on android developers site :
public int onStartCommand (Intent intent, int flags, int startId)
Added in API level 5
You should not override this method for your IntentService. Instead, override onHandleIntent(Intent), which the system calls when the IntentService receives a start request.
Parameters
intent The Intent supplied to startService(Intent), as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY .
flags Additional data about this start request. Currently either 0, START_FLAG_REDELIVERY, or START_FLAG_RETRY.
startId A unique integer representing this specific request to start. Use with stopSelfResult(int).
Returns
The return value indicates what semantics the system should use for the service's current started state. It may be one of the constants associated with the START_CONTINUATION_MASK bits.
See Also
onStartCommand(Intent, int, int)
This says something about how one can get null Intent. But i couldnt understand how to avoid this exception.
Thanks
I am getting the following exception :
java.lang.NullPointerException
at co.riva.vader.PackageUpdateService.onHandleIntent(PackageUpdateService.java:18)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:119)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
package co.riva.vader;
import android.app.IntentService;
import android.content.Intent;
import co.riva.vader.medusa.event.AppInstall;
import co.riva.vader.medusa.event.AppUninstall;
public class PackageUpdateService extends IntentService {
private static final String SERVICE_NAME = "package-update-service";
public PackageUpdateService() {
super(SERVICE_NAME);
}
@Override
protected void onHandleIntent(Intent intent) {
String packageName = intent.getDataString().replace("package:", "");
VaderApp.getLauncherActivitiesManager().update(getPackageManager());
VaderApp.getLauncherAppsManager().updatePackage(getApplicationContext().getPackageManager(), packageName);
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {
if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
VaderApp.getFavouritesManager().removePackage(packageName);
VaderApp.getIconManager().removePackage(packageName);
VaderApp.getMedusaService().report(new AppUninstall(packageName, VaderApp.getLauncherAppsManager().getAll().size()));
}
} else if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
VaderApp.getIconManager().loadAppIcons(packageName);
VaderApp.getMedusaService().report(new AppInstall(packageName, VaderApp.getLauncherAppsManager().getAll().size()));
}
} else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
VaderApp.getIconManager().loadAppIcons(packageName);
}
}
}
I found something on android developers site :
public int onStartCommand (Intent intent, int flags, int startId)
Added in API level 5
You should not override this method for your IntentService. Instead, override onHandleIntent(Intent), which the system calls when the IntentService receives a start request.
Parameters
intent The Intent supplied to startService(Intent), as given. This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY
flags Additional data about this start request. Currently either 0, START_FLAG_REDELIVERY, or START_FLAG_RETRY.
startId A unique integer representing this specific request to start. Use with stopSelfResult(int).
Returns
The return value indicates what semantics the system should use for the service's current started state. It may be one of the constants associated with the START_CONTINUATION_MASK bits.
See Also
onStartCommand(Intent, int, int)
This says something about how one can get null Intent. But i couldnt understand how to avoid this exception.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.