是否可以在我的启动画面中注册C2DM ?
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class myMain extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.isplash);
MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.musicsplash);
mpSplash.start();
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", "my email address");
startService(registrationIntent);
Thread logoTimer = new Thread(){
public void run(){
try{
sleep(4000);
startActivity(new Intent("com.ishop.pizzaoven.CLEARSCREEN"));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
}
是。你可以在任何你喜欢的地方注册C2DM,而且通常越快越好,所以应用程序已经准备好接收信息了。注意,你不需要每次应用程序运行时都重新注册,注册一次,将其存储到pref中,只有在pref为空时才再次注册(例如在卸载/重新安装后)