Bonjour tout le monde,
Je débute tout juste avec le développement sous Android
Et j'ai commencé à develloper une application, mais voilà je suis bloquée sur 3de points le premier et le suivant: Il concerne les services sous Android,
voilà la classe activity et la classe qui étend service:
pourquoi il ne rentre pas dans onCreate(Bundle savedInstanceState) ???

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.exercise.AndroidAlarmService;
 
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
 
public class MyAlarmService extends Service {
 
@Override
public void onCreate() {
// TODO Auto-generated method stub
Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
}
 
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
return null;
}
 
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
}
 
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
}
 
@Override
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this, "MyAlarmService.onUnbind()", Toast.LENGTH_LONG).show();
return super.onUnbind(intent);
}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.exercise.AndroidAlarmService;
 
import java.util.Calendar;
 
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
 
public class AndroidAlarmService extends Activity {
 
private PendingIntent pendingIntent;
 
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonStart = (Button) findViewById(R.id.startalarm);
 
buttonStart.setOnClickListener(new Button.OnClickListener() {
 
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
 
Intent myIntent = new Intent(AndroidAlarmService.this,
MyAlarmService.class);
pendingIntent = PendingIntent.getService(
AndroidAlarmService.this, 0, myIntent, 0);
 
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
 
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar
.getTimeInMillis(), pendingIntent);
}
});
}
}