相关疑难解决方法(0)

如何通过片段获得有关异步任务结果的通知?

我有一个使用片段的Activity.根据用户的交互,这些片段可能会来来去去.其中许多片段将作业发送到IntentService,这样就可以以异步方式运行.IntentService应该如何报告这些工作的结果?

启动该作业的片段可能不存在.如果作业完成且起始片段当前处于活动状态,则应该收到相关通知,并采取相应措施.如果不是,那么就不需要采取任何行动.

我曾考虑使用广播意图和BroadcastReceiver组件,但片段不能注册接收者,只能注册活动.

你会建议什么解决方案?

android android-fragments android-3.0-honeycomb

15
推荐指数
1
解决办法
9224
查看次数

AsyncTask之后的Android刷新片段视图

我正在尝试AsyncTask在我的活动完成时更新列表片段,但我不确定我是否做错了什么.目前,我有一个按钮启动AsyncTask:

search = (Button)findViewById(R.id.search);
    search.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String productname = prodname.getText().toString().trim();
                    if (NetworkManager.isOnline(getApplicationContext())){
                        // Go to Other screen
                        AsyncFetcher results = new AsyncFetcher(currActivity);
                        String _url = "http://192.168.1.3:3000/search.json?
                                       utf8=%E2%9C%93&q="+productname;
                        // progressDialog = ProgressDialog.show(
                        //    ClassifiedsActivity.this, "", "Loading...");
                        results.execute(_url);
                    } else {
                        // Throw some warning saying no internet 
                        // connection was found
                    }
                }
            });
Run Code Online (Sandbox Code Playgroud)

一旦我的执行完成,我就会在我的活动中实例化片段:

ResultFragment resultfrag = new ResultFragment();
getSupportFragmentManager().beginTransaction()
                           .replace(R.id.content_frame, resultfrag).commit();
Run Code Online (Sandbox Code Playgroud)

但是它似乎没有用列表片段替换我的内容.这是我的布局文件:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" …
Run Code Online (Sandbox Code Playgroud)

android fragment android-asynctask

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