Android通过bindservice方式调用服务的方法
来源:互联网 发布:双十一淘宝销售额2016 编辑:程序博客网 时间:2024/06/05 20:46
public class MainActivity extends ActionBarActivity { private MyConn myConn;private MyBinder myBinder;@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent=new Intent(this,BanZhengService.class); myConn = new MyConn(); bindService(intent, myConn,BIND_AUTO_CREATE); } public void click(View v){ myBinder.callBanZheng(10000); } private class MyConn implements ServiceConnection{@Overridepublic void onServiceConnected(ComponentName arg0, IBinder arg1) {myBinder = (MyBinder)arg1;}@Overridepublic void onServiceDisconnected(ComponentName arg0) {// TODO Auto-generated method stub} } @Override protected void onDestroy() { unbindService(myConn); super.onDestroy(); }
public class BanZhengService extends Service {@Overridepublic IBinder onBind(Intent arg0) {return new MyBinder();}public void banZheng(int money){if(money>1000){Toast.makeText(getApplicationContext(),"办事",1).show();}else{Toast.makeText(getApplicationContext(),"不办事",1).show();}}public class MyBinder extends Binder{public void callBanZheng(int money){banZheng(money);}}}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:onClick="click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="124dp" android:text="办事" /></RelativeLayout>
0 0
- Android通过bindservice方式调用服务的方法
- android服务_通过bindService调用服务里的方法
- 通过bindService调用服务里面的方法
- 通过bindservice调用服务内部方法
- android bindService 来调用服务中的方法
- Android通过接口方式调用服务里面的方法
- Android 服务(service)的生命周期以及利用bindservice调用服务里面的方法
- Android 通过接口的方式去调用服务里面的方法
- Android绑定方式开始服务&调用服务当中的方法
- Android中通过接口调用服务里的方法
- bindService调用Service里面方法的步骤
- 为什要使用BindService?为了调用服务中的方法
- Android中BindService方式使用的理解
- Android中BindService方式使用的理解
- Android中BindService方式使用的理解
- Android中BindService方式使用的理解
- Android中BindService方式使用的理解
- Android中BindService方式使用的理解
- PHP输出echo、print、print_r、printf、sprintf、var_dump的区别比较
- Android中的MVP,值得你一看
- JS之联动菜单简单实例
- android 属性动画 介绍
- JS高级基础阶段知识总结
- Android通过bindservice方式调用服务的方法
- 基于 LNMP 搭建个人网站的填坑之旅
- 显示的电池容量不对
- 配置java开发环境
- LINUX命令
- 关于Remote Smart控制电脑的HID的问题
- Asp.Net MVC3 简单入门详解过滤器Filter
- AngularJS行内注入
- IOS移动端meta