Hello;
I want to create my first Android Service running in the background.
So i create an android project under Eclipse. I create the class
ServiceName extends Service like this:
package subpackagename.pack;
import java.util.Timer;
import java.util.TimerTask;
import android.app.AlertDialog;
import android.app.Service;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.IBinder;
public class ServiceName extends Service {
private static final long INTERVAL = 2000;
private Timer timer = new Timer();
public void onCreate() {
super.onCreate();
startservice();
}
private void startservice() {
timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
alert();
}
}, 0, INTERVAL);
; }
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void alert(){
AlertDialog.Builder editDialog = new AlertDialog.Builder
(this);
editDialog.setTitle("Mylink");
editDialog.setMessage("salutttttttttttt");
editDialog.setPositiveButton("Ok", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
} } );
editDialog.setNeutralButton("Cancel", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
} } );
editDialog.show();
}
private void stopservice() {
if (timer != null){
timer.cancel();
}
}
}
I want to display an alert every 2 second (Interval=2000) but the
alert dosen't display.
I added a permission in the AndroidManifest.xml but nothing happened.
My AndroidManifest.xml is like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="subpackagename.pack"
android:versionCode="1"
android:versionName="1.0">
<uses-permission
android:name="android.permission.ACCESS_BACKGROUND_SERVICE" />
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<service android:name=".ServiceName">
</service>
</application>
<uses-sdk android:minSdkVersion="2" />
</manifest>
Thank you for your Help
Thank you.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---