android


android service not starting or giving explict error


I have a service which check for screen on of. I am calling this service from an activity which is mentioned below. Now when i call the service in any device below lollipop it works. It was working with lollipop also. Suddenly it stopped working on lollipop and gives me error
java.lang.IllegalArgumentException: Service Intent must be explicit
no i tried various methods and not able to understand whats happening.....
package com.androidexample.screenonoff;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class AEScreenOnOffService extends Service {
BroadcastReceiver mReceiver=null;
#Override
public void onCreate() {
super.onCreate();
// Toast.makeText(getBaseContext(), "Service on create", Toast.LENGTH_SHORT).show();
// Register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new AEScreenOnOffReceiver();
registerReceiver(mReceiver, filter);
}
#Override
public void onStart(Intent intent, int startId) {
boolean screenOn = false;
try{
// Get ON/OFF values sent from receiver ( AEScreenOnOffReceiver.java )
screenOn = intent.getBooleanExtra("screen_state", false);
}catch(Exception e){}
// Toast.makeText(getBaseContext(), "Service on start :"+screenOn,
//Toast.LENGTH_SHORT).show();
if (!screenOn) {
// your code here
// Some time required to start any service
//Toast.makeText(getBaseContext(), "Begin ", Toast.LENGTH_LONG).show();
// Intent yourintent = new Intent(this, postlockscreen.class);
//yourintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//startActivity(yourintent);
} else {
// your code here
// Some time required to stop any service to save battery consumption
//Toast.makeText(getBaseContext(), "Screen off,", Toast.LENGTH_LONG).show();
Intent yourintent = new Intent(this, postlockscreen.class);
yourintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(yourintent);
}
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
No when i start the service from any device lesser than lollipop it starts the service and works fine
package com.androidexample.screenonoff;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class ScreenOnOff extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_on_off);
// Start AEScreenOnOffService Service
Intent i0 = new Intent();
i0.setAction("com.androidexample.screenonoff.AEScreenOnOffService");
startService(i0);
//startService(new Intent(this, AEScreenOnOffService.class));
}
}

Related Links

How to troubleshoot startup of Android emulator from inside Eclipse?
Reticle not detecting button
How to access localhost (xampp, phpmyadmin, etc.) from an Android device?
Error:CreateProcess error=193, %1 is not a valid Win32 application
FirebaseRecyclerAdapter populateViewHolder NullPointerException
Receive messages from 2 different senders in FCM [duplicate]
android - piece of code used to find current location not working
Looper.Loop() exception inside invoked method
PN532 NFC RFID - Elechouse | After set password on tags
creating Navigation Drawer in android xamarin
load images and clicking on previous button doesnot load the image in android
Android dependency graph
Selecting item of sliding tabs menu from navigation drawer with some fragment
Android service get foreground app, Android API 23
com.android.builder.internal.aapt.AaptException: Failed to crunch file PNG file
I want to disable preloading next page in a ViewPager

Categories

HOME
phantom-dsl
search
c++11
pda
rsa
camera
sitecore
solver
ms-access-2016
bitbucket-api
newrelic
nsbundle
3d-reconstruction
data-visualization
angularfire2
retrofit2
opengl-3
pkcs#11
windows-ce
stellar.js
endpoint
selenium-ide
code-generation
libusb
ember-cli
imageresizer
resourcebundle
itunes
jackson-modules
amazon-quicksight
angular-translate
soot
quantlib
comparable
iis-express
sqlpackage
autodesk-designautomation
powershell-ise
cognos-bi
left-join
cart
quickfixj
wacom
android-gridview
swagger-php
urlsession
news
tasm
dcmtk
portforwarding
signal-strength
flask-login
oim
magento-2.0.7
openrasta
netbeans6.8
tf
datamaps
openblas
context-sensitive-grammar
skin
gameplay-kit
vcloud-director-rest-api
visual-studio-2008-sp1
latin
preprocessor
google-cloud-console
async.js
watch-os-2
x-tag
mapinfo
hclust
dup
expectations
phpwebsocket
sklearn-pandas
invoke-sqlcmd
inf
dynamics-nav-2016
linklabel
decimalformat
themoviedb-api
xenomai
airbrake
cwrsync
snoop
boost-program-options
contrast
easyrtc
kissfft
alternate
buffering
authlogic
ora-06550
scriptaculous
mysql-error-1044
c++builder-xe5
windows-phone-8-sdk
modular
observium
font-awesome-4.0.0
redis-py
jquery-blockui
veracity
pyunit
inkcanvas
agility.js
user-tracking
umra
massive
http-daemon
cloudfiles
presentation-layer
squishit
non-clustered-index
escrow
soappy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App