query regarding Service

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

query regarding Service

Postby newborn » Wed Nov 26, 2008 4:47 pm

Hi Experts,

Today i joined the forum, decided to start Android. Hope My journey will be smooth. :)

I am having few questions regarding Services:

1. How to create a Service which will be running in background ?
2. Whenever i should start my phone/emulator it should be running in the background automatically.
3. How to create .aidl file and .java from it ?
4. How to see a service running on phone/emulator?


Regards
newborn
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:33 pm

Top

Postby MrSnowflake » Wed Nov 26, 2008 7:50 pm

If you are new to Android then start reading the Documentation in the SDK!
1 and 3 are in there.
2 has be discussed here before (a lot).
and 4 ... What do you mean with that :). You can write to the Log from your service.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby newborn » Thu Nov 27, 2008 2:53 am

MrSnowflake wrote:If you are new to Android then start reading the Documentation in the SDK!
1 and 3 are in there.
2 has be discussed here before (a lot).
and 4 ... What do you mean with that :). You can write to the Log from your service.


Ok, i will do the suggested things first then get back to you.

Regard
newborn
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:33 pm

Postby newborn » Thu Nov 27, 2008 7:47 am

MrSnowflake wrote:If you are new to Android then start reading the Documentation in the SDK!
1 and 3 are in there.
2 has be discussed here before (a lot).
and 4 ... What do you mean with that :). You can write to the Log from your service.


Hi Snowflake,

As per you said i read that document, i made one simple service (only service no other activity) without .aidl file, in one project, the code is:

in .java file

public class TestService extends Service
{
/** Called when the activity is first created. */
@Override
public void onCreate()
{
super.onCreate();
}

public IBinder onBind(Intent intent)
{
return null;
}

public void onDestroy()
{
super.onDestroy();
//Log.d( "ADDERSERVICEIMPL","onDestroy" );
}

public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
Toast.makeText(this, "Service Started", 5000);
}

}

in menifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.TestService"
android:versionCode="1"
android:versionName="1.0.0">
<application>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
<service android:name=".TestService"/>
</application>
</manifest>


Now i create another project of library type (not an android project, so not having Menifest.xml file) from where i want to use the above Service, the code is :

abstract public class snServices extends BroadcastReceiver
{

public void onReceive(Context context, Intent intent)
{

Intent myStarterIntent = new Intent(context, TestService.class);
myStarterIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(myStarterIntent);
}

}

But, now it is giving error at "Intent myStarterIntent = new Intent(context, TestService.class); " line , the error is : TestService cannot be resolved to a type.

Now my question is:
1. How to consume a service in this type of scenario?


Regards
newborn
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:33 pm

Postby MrSnowflake » Thu Nov 27, 2008 1:55 pm

You probably have to use intent-filters in the manifest of the service and use those to get a connection to the service.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby newborn » Thu Nov 27, 2008 2:29 pm

MrSnowflake wrote:You probably have to use intent-filters in the manifest of the service and use those to get a connection to the service.


Thanks For the quick reply,

Exactly what i have to write in Service's Menifest.xml as Intent-filter so that its class is accessible from my another apps, its not clear to me, can you pls. provide me taking above application as an example and modify the menifest.xml which is present in this post ?

Best Regards
newborn
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:33 pm

Top

Postby newborn » Fri Nov 28, 2008 6:08 am

Hi Experts,

Any suggestions on the above problem ?

Regards
newborn
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:33 pm

Postby newborn » Fri Nov 28, 2008 8:01 am

Hi All,

How to invoke Remote Service from an application ?

Regards
newborn
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:33 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests