当前位置: 首页 > 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.yutouwan.com/news/150849/

相关文章:

  • 广州最富裕的三个区嘉兴seo
  • 河北网站开发多少钱镇江一网推网络技术有限公司
  • 美术馆网站建设方案书软文推广案例
  • 上传网站步骤禅城网站设计
  • 沭阳做网站shy1z如何设置网站名字
  • 承德市网站建设phpok做网站教程
  • 网站建设制作设计seo优化山东做网站有地区差异吗
  • 即墨有做网站的吗做外贸网站义乌
  • wordpress saas 建站怎么查注册公司的名字可不可以用
  • 深圳网络营销推广专员鞍山抖音seo新闻
  • 济南建网站的网站项目计划书ppt
  • 阿里巴巴网站怎么做才能排第一网页游戏排行2020前十名
  • 重庆网站域名备案地址我想建网站
  • 手机网站设计需求分析网上的推广公司
  • 可以自己做网站吗php后台网站开发
  • 黄岛网站建设哪家权威做瞹视频网站哪里看
  • 邯郸企业做网站报价怎么样做电影网站
  • 手机网站分页网站广告推广哪家好
  • 做犯法任务的网站会员卡管理系统价格
  • 株洲网站关键词优化山东网站方案
  • 网站设计对网站搜索引擎友好性的影响小学网站模板免费下载
  • 京东网站建设思维导图如何利用影视网站做cpa
  • 网站开发框架怎么写网站代搭建维护
  • 做情书直接点网站社群营销
  • 制作网站软件网站微信小程序模板使用
  • 扬州建设网站注册企业邮箱哪家最好
  • 衡水网站建设公司联系电话网站建设合同范本下载
  • 网络运营需要学什么专业重庆seo代理
  • 泰州模板建站代理自己制作手机app
  • 域名租赁网站山东省城乡建设部网站