混合开启服务
来源:互联网 发布:不教翠羽遇萧峰 知乎 编辑:程序博客网 时间:2024/04/28 17:05
public class MainActivity extends AppCompatActivity { private MyCon myCon; MySer.MyB binder; //混合开启服务 先star 再bind22 再jiebang 服务不会被销毁 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void star(View view) { System.out.println("ddddddddddddddddd"); startService(new Intent(this, MySer.class)); } public void stop(View view) { stopService(new Intent(this, MySer.class)); } public void bind22(View view) { myCon = new MyCon(); bindService(new Intent(this,MySer.class),myCon,BIND_AUTO_CREATE); } public void jiebang(View view) { unbindService(myCon); } public void sc(View view) { binder.call(); } class MyCon implements ServiceConnection{ @Override public void onServiceConnected(ComponentName name, IBinder service) { System.out.println("MyCon.onServiceConnected"); binder= (MySer.MyB) service; } @Override public void onServiceDisconnected(ComponentName name) { System.out.println("MyCon.onServiceDisconnected"); } } @Override protected void onDestroy() { super.onDestroy(); } } public class MySer extends Service { @Override public IBinder onBind(Intent intent) { System.out.println("MySer.onBind"); return new MyB(); } @Override public void onCreate() { System.out.println("MySer.onCreate"); super.onCreate(); } @Override public void onDestroy() { System.out.println("MySer.onDestroy"); super.onDestroy(); } @Override public boolean onUnbind(Intent intent) { System.out.println("MySer.onUnbind"); return super.onUnbind(intent); } @Override public int onStartCommand(Intent intent, int flags, int startId) { System.out.println("MySer.onStartCommand"); return super.onStartCommand(intent, flags, startId); } public void callServices() { System.out.println("调取到服务里面的方法了"); Toast.makeText(this,"我就是",Toast.LENGTH_LONG).show(); } public class MyB extends Binder { public void call() { callServices(); } } }
0 0
- 混合开启服务
- 混合开启服务
- 混合的方式开启服务
- Android混合方式开启服务
- 混合调用和开启服务的生命周期
- 混合方式开启服务的特点
- 混合模式开启服务的特点
- 使用混合方式开启服务----百度音乐盒框架的搭建
- Android服务Service详解(作用,生命周期,AIDL)系列文章--服务绑定和开启混合使用
- 混合调用服务
- 开启服务和绑定服务
- 开启ssh服务
- 开启FTP服务
- Ubuntu开启telnet服务
- 开启SQL Server服务
- Ubuntu开启telnet服务
- 系统开启的服务
- CMD 开启 停止服务
- 使用QuartZ定时发送邮件
- 三洋献瑞
- Lake Counting POJ
- 数据库三大范式详解(通俗易懂)
- Ubuntu服务器入门指南
- 混合开启服务
- nyoj 1187 模拟2048
- MySQL命令(详细)
- 501. Find Mode in Binary Search Tree\492. Construct the Rectangle\*486. Predict the Winner\输出一个level
- 操作系统各大知识模块
- Sql Server查询语句
- hduoj-5311【dfs】
- Android异步实现——IntentService
- 3.11考试