zoukankan      html  css  js  c++  java
  • Android 启动Service服务和发送Broadcast广播的常用方法

    一、先说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);
  • 相关阅读:
    onclick中的函数的参数this
    classList的使用
    设置点击鼠标时不跳转
    模块补充shutil,logging
    re模块拾遗和递归函数
    正则表达式-re模块
    软件开发规范
    自定义模块2
    常用模块
    初识自定义模块
  • 原文地址:https://www.cnblogs.com/bluejump/p/4529941.html
Copyright © 2011-2022 走看看