Android 启动Service服务和发送Broadcast广播的常用方法

时间:2015-05-26 12:03:58   收藏:0   阅读:501

一、先说Service服务。

  1、利用setAction()方法来指定启动的Service服务

1 Intent intent = new Intent();
2 intent.setAction("ServiceAction");
3 startService(intent);

  2、使用Intent的构造函数类添加Activity内容

1 Intent intent = new Intent("ServiceAction");
2 startService(intent);

  3、和Activity之间跳转类似

1 Intent intent = new Intent(MainActivity.this,ServiceTest.class);
2 startService(intent);

二、再看Broadcast广播

  1、利用setAction()方法来指定发送的Broadcast广播

1 Intent intent = new Intent();
2 intent.setAction("BroadcastAction");
3 sendBroadcast(intent);

  2、使用Intent的构造函数类添加Activity内容

1 Intent intent = new Intent("BroadcastAction");
2 sendBroadcast(intent);

  3、和Activity之间跳转类似

1 Intent intent = new Intent(MainActivity.this,BroadcastTest.class);
2 sendBroadcast(intent);

 

原文:http://www.cnblogs.com/bluejump/p/4529941.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!