基本信息
源码名称:RxJava示例源码(请求网络数据+loading效果)
源码大小:27.86M
文件格式:.rar
开发语言:Java
更新时间:2018-03-14
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package laobi.com.rxjavademo.activity; import android.content.Intent; import android.databinding.DataBindingUtil; import android.graphics.Bitmap; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.util.Log; import android.view.View; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import laobi.com.rxjavademo.R; import laobi.com.rxjavademo.RxService; import laobi.com.rxjavademo.ServiceFactory2; import laobi.com.rxjavademo.bean.RetrofitEntity; import laobi.com.rxjavademo.databinding.ActivityMainBinding; import laobi.com.rxjavademo.net.DefaultObserver2; import laobi.com.rxjavademo.utils.ToastUtils; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final String TAG = "date"; private ActivityMainBinding mBinding; private Bitmap mBitmap = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); mBinding.getResult.setOnClickListener(this); mBinding.rxJava.setOnClickListener(this); //以兆(M)为单位 //也可以在Android Monitor的Monitors查看 // Log.e(TAG, "系统现在分配给app的大小:" Runtime.getRuntime().totalMemory() * 1.0f /(1024*1024) ); // Log.e(TAG, "空闲内存大小:" Runtime.getRuntime().freeMemory() * 1.0f /(1024*1024) ); // Log.e(TAG, "内存总大小:" Runtime.getRuntime().maxMemory() * 1.0f /(1024*1024) ); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.get_result: sendRequestFromServer(); break; case R.id.rx_java: startActivity(new Intent(this, RxjavaTestActivity.class)); break; } } private void sendRequestFromServer() { ServiceFactory2.getInstance().create(RxService.class) .getAllVedioBy(true) // .compose(this.<BasicResponse<RetrofitEntity>>bindToLifecycle())//绑定生命周期 .subscribeOn(Schedulers.io()) .unsubscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new DefaultObserver2<RetrofitEntity>(this) { @Override protected void onFail(RetrofitEntity response) { String message = response.getMessage(); if (TextUtils.isEmpty(message)) { ToastUtils.show(R.string.response_return_error); } else { ToastUtils.show(message); } } @Override public void onSuccess(RetrofitEntity response) { mBinding.result.setText(response.getData().toString()); Log.e(TAG, "accept: " response.getData().toString()); } } ); } }