如何修复已弃用:startManagingCursor()

时间:2015-05-19 12:34:09

标签: android android-loadermanager android-loader

我有一个绝望的代码

startManagingCursor(timelineCursor)

该代码不再起作用,但我如何更改我的代码使用loadmanager,我已经阅读了一些博客,但我仍然感到困惑。你能举个例子吗?

这是我的完整代码

setContentView(R.layout.timeline);
        try {  

        homeTimeline = (ListView)findViewById(R.id.homeList);
        //instantiate database helper 
        timelineHelper = new NiceDataHelper(this);   
        //get the database 
        timelineDB = timelineHelper.getReadableDatabase();
         //query the database, most recent tweets first 
        timelineCursor = timelineDB.query("home", null, null, null, null, null, "update_time DESC");
        startManagingCursor(timelineCursor);
        //instantiate adapter 
        timelineAdapter = new UpdateAdapter(this, timelineCursor);
        //this will make the app populate the new update data in the timeline view 
        homeTimeline.setAdapter(timelineAdapter);
        //instantiate receiver class for finding out when new updates are available 
        niceStatusReceiver = new TwitterUpdateReceiver(); 
        //register for updates 
        registerReceiver(niceStatusReceiver, new IntentFilter("TWITTER_UPDATES"));
        Toast.makeText(getApplicationContext(), "teest", Toast.LENGTH_SHORT).show();
        //start the Service for updates now 
        this.getApplicationContext().startService(new Intent(this.getApplicationContext(), TimeLineService.class));

        } 
    catch(Exception te) { Log.e(LOG_TAG, "Failed to fetch timeline: " + te.getMessage()); }

1 个答案:

答案 0 :(得分:0)

装载机框架的工作一旦发生故障就不难理解。您将需要使用管理器以及一组自己的自定义回调。本文应该有助http://hiqes.com/android-loaders/