相关疑难解决方法(0)

AsyncTaskLoader基本示例.(机器人)

我在我的应用程序中使用Loader,并根据我使用此Loader在COntacts上执行的查询得到的结果,我执行一些计算并将它们存储回Sqlite DB中.我希望这个操作是异步的,但我在使用Async任务之间感到困惑,因为我要返回很多不同的数据类型,或者我应该使用简单的处理程序或AsyncTaskLoader,我希望它很简单,因为我是新手装载机.我试图搜索AsyncTaskLoader的例子,但它似乎是火箭科学,在我的场景的上下文中的三个中的任何一个的基本和简单的功能示例将是非常有帮助的.

android android-asynctask android-handler

22
推荐指数
4
解决办法
5万
查看次数

通过底部导航栏更改片段时恢复片段状态

我点击导航栏中的项目底部导航栏我正在替换片段.我有3个片段A,B,C所以点击b项B片段加载,在B我调用3-4个API.所以,现在如果我转到C然后再次来到B,就会创建一个新的B Fragment实例,并再次调用这些API,如何保存片段实例状态,而不是在更改片段时再次调用API.这是我的代码.

mBottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            int id = item.getItemId();
            Fragment currentLoaded = fgMan.findFragmentById(R.id.container_body);
            switch (id) {
                case R.id.nearby_fragment:
                    if (!(currentLoaded instanceof SpotFeedMapFragment)) {
                        removeScroll();
                        mNearByFragment = fgMan.findFragmentByTag(NEARBY_FRAGMENT_TAG) != null ? fgMan.findFragmentByTag(NEARBY_FRAGMENT_TAG) : mNearByFragment;
                        fgMan.beginTransaction().setCustomAnimations(R.anim.abc_fade_in, R.anim.abc_fade_out);
                        fgMan.beginTransaction().replace(R.id.container_body, mNearByFragment, NEARBY_FRAGMENT_TAG).commit();
                        fgMan.executePendingTransactions();
                        getSupportActionBar().setTitle(getString(R.string.nearby_fragment));
                    }
                    break;
                case R.id.route_fragment:
                    if (!(currentLoaded instanceof BusLocationsFragment)) {
                        if (!inParent) {
                            mRl.removeView(fixLayout);
                            p.addRule(RelativeLayout.BELOW, toolbar.getId());
                            scrollView.setLayoutParams(p);
                            scrollView.addView(fixLayout);
                            mRl.addView(scrollView);
                            inParent = true;
                        }
                        //mFragment = new BusLocationsFragment();
                        mBusLocFragment = fgMan.findFragmentByTag(BUS_LOC_FRAGMENT_TAG) != null ? fgMan.findFragmentByTag(BUS_LOC_FRAGMENT_TAG) …
Run Code Online (Sandbox Code Playgroud)

android navigationbar android-fragments bottomnavigationview

16
推荐指数
3
解决办法
1万
查看次数