Home How can I implement AsyncTask into my current Activity
Reply: 0

How can I implement AsyncTask into my current Activity

user2796 Published in June 23, 2018, 9:21 pm

An Activity in my Android application is incredibly slow to load, it's loading Tweets into a RecyclerView using TwitterKit. LogCat displays the following message: "

Skipped 1491 frames! The application may be doing too much work on its main thread"

After some research, I understand that I need to Implement AsyncTask to move the workload away from the main thread. I've attempted to implement it, however, I cannot get it to work. A point in the correct direction would be much appreciated. Please see code below

import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;

//twitter imports

import com.twitter.sdk.android.core.Twitter;
import com.twitter.sdk.android.tweetui.TweetTimelineRecyclerViewAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;

public class travel_updates extends AppCompatActivity{

    protected void onCreate(@Nullable Bundle savedInstanceState) {

        View view = getSupportActionBar().getCustomView();


workHorse workhorse = new workHorse();

        final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));


    private class workHorse extends AsyncTask<String, Void, String>{

        protected void onPreExecute() {

        protected String doInBackground(String... params) {

            final UserTimeline searchTimeline = new UserTimeline.Builder().screenName("TflTravelAlerts")

            final TweetTimelineRecyclerViewAdapter adapter =
                    new TweetTimelineRecyclerViewAdapter.Builder(this)

        protected void onPostExecute(String s) {
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307645 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO