Starting up a service

Put your problem here if it does not fit any of the other categories.

Starting up a service

Postby jimmyk » Thu Jan 31, 2008 12:30 pm

Hello there, i'm quite new to Android and i've been reading a few posts about invoking services.

Now i've made a nice UI wit a few buttons and i want one of those buttons to start up a service. So i put this code into the onClick method:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Intent intent = new Intent(<Nameofthisclass>.this, <nameofserviceclass>.class);
  3.  
  4. intent.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
  5.  
  6. startService(intent, null);
  7.  
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


In the class that's being called i put a showAlert to see if it's actually being called, but it doesn't. Am i doing anything wrong, maybe i need to define the service in the AndroidManifest.xml :?:

Tnx in regard :D
jimmyk
Freshman
Freshman
 
Posts: 2
Joined: Thu Jan 31, 2008 12:19 pm
Location: Netherlands

Top

Postby AndreySerj » Thu Jan 31, 2008 1:27 pm

Yes, You need to describe your service in the AndroidManifest.xml:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. <service class=".<nameofserviceclass>" android:process=":remote"/>
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

And, IMHO, this line
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. intent.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
is unnecessary.
AndreySerj
Developer
Developer
 
Posts: 31
Joined: Wed Dec 26, 2007 9:57 am
Location: Minsk

Postby jimmyk » Thu Jan 31, 2008 2:55 pm

Tnx for your help, it's working now :).
jimmyk
Freshman
Freshman
 
Posts: 2
Joined: Thu Jan 31, 2008 12:19 pm
Location: Netherlands

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 23 guests