当前位置: 首页 > news >正文

怎么做微信上的网站吗如果在网站做推广连接

怎么做微信上的网站吗,如果在网站做推广连接,公众号如何做网站,网站建设推广代运营Android Broadcast 广播 进程内本地广播 如果你是在你的应用之内使用广播#xff0c;即不需要跨进程#xff0c;考虑使用LocalBroadcastManager #xff0c;这样更有效率#xff08;因为不需要跨进程通信#xff09;#xff0c;并且你不用考虑一些其他应用可以发送或接收…  Android Broadcast 广播   进程内本地广播   如果你是在你的应用之内使用广播即不需要跨进程考虑使用LocalBroadcastManager 这样更有效率因为不需要跨进程通信并且你不用考虑一些其他应用可以发送或接收你的广播相关的安全问题。     下面介绍更一般的方法。   广播的两种注册方法   广播有静态和动态两种注册方法   静态注册在AndroidManifest.xml中加上receiver 标签。   动态注册通过 Context.registerReceiver()方法进行注册。比如在onResume中注册在onPause中注销。     附上例子例子中的布局、MyReceiver类常量类都是相同的在前面列出   布局文件都一样   RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:paddingBottomdimen/activity_vertical_marginandroid:paddingLeftdimen/activity_horizontal_marginandroid:paddingRightdimen/activity_horizontal_marginandroid:paddingTopdimen/activity_vertical_margintools:context.DemoBroadcastActivity TextViewandroid:idid/helloTextandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textstring/hello_world /Buttonandroid:idid/sendBtnandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_belowid/helloTextandroid:textstring/send //RelativeLayout       自己写的Receiver类 import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Toast;public class MyReceiver extends BroadcastReceiver {public MyReceiver(){super();Log.d(AppConstants.LOG_TAG, Receiver constructor);}Overridepublic void onReceive(Context context, Intent intent){Log.d(AppConstants.LOG_TAG, onReceive);String message intent.getStringExtra(AppConstants.MSG_KEY);Log.i(AppConstants.LOG_TAG, message);Toast.makeText(context, Received! msg: message, Toast.LENGTH_SHORT).show();}}   应用常量 public class AppConstants {public static final String LOG_TAG Broadcast;public static final String MSG_KEY msg;public static final String BROADCAST_ACTION com.example.demobroadcast.BroadcastAction;}     下面就是不同的部分了     静态注册的实例代码   静态注册是在manifest文件中进行: ?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://schemas.android.com/apk/res/androidpackagecom.example.demobroadcastandroid:versionCode1android:versionName1.0 uses-sdkandroid:minSdkVersion8android:targetSdkVersion17 /uses-permission android:nameandroid.permission.RECEIVE_SMS /uses-permission android:nameandroid.permission.SEND_SMS /applicationandroid:allowBackuptrueandroid:icondrawable/ic_launcherandroid:labelstring/app_nameandroid:themestyle/AppTheme activityandroid:namecom.example.demobroadcast.DemoBroadcastActivityandroid:labelstring/app_name intent-filter android:priority1000action android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER //intent-filter/activityreceiverandroid:namecom.example.demobroadcast.MyReceiverintent-filter action android:namecom.example.demobroadcast.BroadcastAction //intent-filter/receiver/application/manifest     所以Java代码 package com.example.demobroadcast;import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import android.app.Activity; import android.content.Intent;public class DemoBroadcastActivity extends Activity {private Button sendBtn null;Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_demo_broadcast);sendBtn (Button) findViewById(R.id.sendBtn);sendBtn.setOnClickListener(new OnClickListener(){Overridepublic void onClick(View v){Intent intent new Intent();intent.setAction(AppConstants.BROADCAST_ACTION);intent.putExtra(msg, 圣骑士wind);sendBroadcast(intent);}});}}       动态注册的实例代码:   动态注册是在Java代码中进行   package com.example.demobroadcast2;import com.example.demobroadcast.R;import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import android.app.Activity; import android.content.Intent; import android.content.IntentFilter;public class DemoBroadcastActivity extends Activity {private Button sendBtn null;private MyReceiver mReceiver;Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_demo_broadcast);sendBtn (Button) findViewById(R.id.sendBtn);sendBtn.setOnClickListener(new OnClickListener(){Overridepublic void onClick(View v){Intent intent new Intent();intent.setAction(AppConstants.BROADCAST_ACTION);intent.putExtra(msg, 圣骑士wind);sendBroadcast(intent);}});}Overrideprotected void onResume(){super.onResume();mReceiver new MyReceiver();IntentFilter intentFilter new IntentFilter(AppConstants.BROADCAST_ACTION);registerReceiver(mReceiver, intentFilter);}Overrideprotected void onPause(){super.onPause();unregisterReceiver(mReceiver);}Overrideprotected void onDestroy(){super.onDestroy();}}     所以Manifest文件中不需要添加标签正常就行。     两种广播   Normal broadcasts   通过 Context.sendBroadcast发送完全是异步的asynchronous。所有的接收器以不确定的顺序运行通常是同时。   这样更有效率但是也意味着接收器不能传递结果也不能退出广播。   Ordered broadcasts   通过 Context.sendOrderedBroadcast发送。一次只向一个接收器发送。   由于每个接收器按顺序执行它可以向下一个接收器传递结果也可以退出广播不再传递给其他接收器。   接收器运行的顺序可以通过 android:priority 属性来控制相同优先级的接收器将会以随机的顺序运行。   接收器的生命周期   一个BroadcastReceiver的对象只在 onReceive(Context, Intent)被调用的期间有效一旦从这个方法返回系统就认为这个对象结束了不再活跃。   这对你在onReceive中能做什么有很大的影响不能做任何需要的操作anything that requires asynchronous operation is not available。   因为你需要从方法返回去进行你的异步操作而返回时BroadcastReceiver的对象已经不再活跃了系统可以在异步操作完成前任意杀死它的进程。   特别地不可以在BroadcastReceiver中显示对话框或者绑定一个service前者应该用 NotificationManager后者应该用Context.startService()。   参考资料   官方文档BroadcastReceiver   http://developer.android.com/reference/android/content/BroadcastReceiver.html   LocalBroadcastManager   http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html    Training: Manipulating Broadcast Receivers On Demand   http://developer.android.com/training/monitoring-device-state/manifest-receivers.html   receiver标签   http://developer.android.com/guide/topics/manifest/receiver-element.html      转载于:https://www.cnblogs.com/mengdd/archive/2013/06/14/3135431.html
http://www.huolong8.cn/news/150849/

相关文章:

  • 网站再就业培训班陕西网站开发公司地址
  • 婚礼做的好的婚庆公司网站金川做网站公司
  • 京东的网站是哪家公司做的制作网页然后把文件上传
  • 福永网站建设多少钱自己的服务器如何做网站
  • 怎么在搜索引擎做网站登记广州做网站开发
  • 昆山 网站建设彩票网站建设与推广
  • 饲料行业怎么做网站开发cms网站系统
  • 石狮网站建设公司注册城乡规划师准考证打印时间
  • 做棋盘游戏辅助的网站装饰网站卧室做炕百度
  • 网站服务器 试用温州模板建站代理
  • 怎么做好邯郸网站建设php网站开发全程实例
  • html5做网站的总结wordpress ssh
  • 行业网站维护wordpress菜单手机显示下拉
  • 数码网站名福田网络推广公司
  • 南京门户网站网站制作企业有哪些
  • 网站建设技术线路选择ktv网站模板
  • 怀来县住房和城乡规划建设局网站中卫网红美食打卡地
  • 计算机网络资源网站建设论文电商平台开发需要哪些技术人员
  • 南京网站南京网站开发住房和城乡建设部监理网站
  • 猫扑网站开发的网络游戏光遇网页制作素材
  • 做外链的博客网站嵌入式开发要学哪些课程
  • 做网站销售有前景吗ps简单网页设计模板图片
  • wordpress单图模式广安seo外包
  • 一个虚拟空间可以做两个网站吗三门峡网站设计
  • 深圳企业网站定制公司wordpress转换为中文版
  • 网站后台会员管理网站设网站设计
  • 那个免费做微信订阅号的网站海南省建设培训与职业资格注册中心网站
  • 商丘睢阳区市政建设局网站景安安装wordpress提示错误
  • 网站建设流程总结邢台163信息网
  • 苏州市建设工程质量监督站网站网站子目录设计