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 store video files in database in android applications
android save content on setContentView()
Get a pixels/units relation with opengl es
Android XML.parse() not finding content:encoded tag
Android ListView divider near group header
DialogFragment with extra space below ListView
Running the new Intel emulator for Android
How to make the video display from sdcard in android?
Android: how to show icon in ActionBar but not in the Options Menu?
Admob cant find transfer funds link in google admob panel [closed]
Expandable ListView with JSON Data in android
Getting Error while configuring ADB
ComponentInfo{packgname.LoginActivity}: java.lang.ClassNotFoundException
List view values cause an error
Restart of an Android activity after a long time of idleness -> NullPointerException
how to generate cmap_cns.h in mupdf

Categories

HOME
service-worker
google-app-engine
gridview
paraview
linkedin
dns
mjml
interface
jsf-2.2
spring-data-redis
cakephp-3.4
azure-container-service
jtextpane
little-proxy
android-securityexception
mautic
ipmitool
intercom
favicon
qsqlquery
heat
vuejs
template-engine
wolframalpha
imessage
sse
cfml
lilypond
breadth-first-search
jquery-ias
inno-download-plugin
easeljs
game-theory
dapper-extensions
windows-server-2003
moses
winexe
subclass
sqsh
event-flow
kudu
turfjs
simplecv
classcastexception
installscript
pdw-file-browser
processwire
navigator
latitude-longitude
salesforce-communities
jvmti
apache-stanbol
resolution
vmware-fusion
levenshtein-distance
wc
apache-spark-dataset
stylecop
uiimage
cnc
singleinstance
janus
gameplay-kit
filenet
javafx-css
testrail
chromium-os
async.js
spring-cloud-feign
macaulay2
expectations
nservicebus5
deep
bizagi
data-protection
gcloud-ruby
boost-serialization
database-relations
aspen
fiware-monitoring
fuelcms
mirror
apache-commons-daemon
botan
google-refine
fail2ban
public-html
at-job
jbake
iiop
sql-scripts
appserver
imagefilter
lambda-architecture
renderer
square-bracket
amslidemenu
bin
eclipse-kepler
ebay-lms
kaleidoscope
composite-component
stacky
dajaxice
cgimage
virtualpathprovider
denied
load-time
silent
burndowncharts
lxr
complex-event-processing
fdf
business-model

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