簡體   English   中英

循環中的活動-執行停止的未恢復的活動

[英]Activity in loop - Performing stop of activity that is not resumed

我的主要活動顯示此錯誤:

執行停止的活動未恢復

這是我的Logcat:

11-20 01:20:16.640 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: CREATED
11-20 01:20:16.740 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: STARTED
11-20 01:20:16.740 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: RESUMED
11-20 01:20:17.173 19746-19803/com.podchest.podchest D/JSON Parser: result: {"podcast":[{"nome":"Ludocast Brasil","link":"http:\/\/www.ludopedia.com.br\/podcast\/1\/ludocast\/feed","imagem":"http:\/\/www.ludopedia.com.br\/uploads\/01\/504\/s9mg0r.png","nome_cat":"Jogos","nome_autor":"Ludocast Brasil"}]}
11-20 01:20:17.173 19746-19803/com.podchest.podchest D/JSON result: {"podcast":[{"nome":"Ludocast Brasil","link":"http:\/\/www.ludopedia.com.br\/podcast\/1\/ludocast\/feed","imagem":"http:\/\/www.ludopedia.com.br\/uploads\/01\/504\/s9mg0r.png","nome_cat":"Jogos","nome_autor":"Ludocast Brasil"}]}
11-20 01:20:17.173 19746-19803/com.podchest.podchest D/QFOI: Ludocast Brasil
11-20 01:20:17.173 19746-19803/com.podchest.podchest D/IMPOSSIVEL:: http://www.ludopedia.com.br/podcast/1/ludocast/feed
11-20 01:20:17.211 19746-19746/com.podchest.podchest D/MAIN =====>: administrador@podchest.com
11-20 01:20:17.242 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: CREATED
11-20 01:20:17.243 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: STARTED
11-20 01:20:17.244 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: RESUMED
11-20 01:20:17.385 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: RESUMED
11-20 01:20:17.664 19746-19746/com.podchest.podchest D/MAIN =====>: administrador@podchest.com
11-20 01:20:17.700 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: CREATED
11-20 01:20:17.701 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: STARTED
11-20 01:20:17.701 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: RESUMED
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread: Performing stop of activity that is not resumed: {com.podchest.podchest/com.podchest.podchest.MainActivity}
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread: java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.podchest.podchest/com.podchest.podchest.MainActivity}
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3396)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3477)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at android.app.ActivityThread.access$1100(ActivityThread.java:148)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at android.os.Looper.loop(Looper.java:135)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at android.app.ActivityThread.main(ActivityThread.java:5312)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at java.lang.reflect.Method.invoke(Native Method)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at java.lang.reflect.Method.invoke(Method.java:372)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
11-20 01:20:17.709 19746-19746/com.podchest.podchest E/ActivityThread:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
11-20 01:20:17.710 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: RESUMED
11-20 01:20:18.014 19746-19746/com.podchest.podchest D/MAIN =====>: administrador@podchest.com
11-20 01:20:18.053 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: CREATED
11-20 01:20:18.055 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: STARTED
11-20 01:20:18.055 19746-19746/com.podchest.podchest D/LIFECYCLE =====>: RESUMED

主要活動:

    package com.podchest.podchest;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
    private RecyclerView.Adapter mAdapter;
    private RecyclerView.LayoutManager mLayoutManager;
    ProgressDialog pDialog;
    Helper meuhelper;
    JsonParser jsonParser;
    SessionManager sessionManager;

    private static final String TAG_SUCCESS = "success";
    private static final String TAG_MESSAGE = "message";
    private static final String TAG_PODCASTS = "podcast";
    private static final String TAG_ID = "id";
    private static final String TAG_NOME = "nome";
    private static final String TAG_AUTOR = "nome_autor";
    private static final String TAG_CATEGORIA = "nome_cat";
    private static final String TAG_LINK = "link";
    //private static final String TAG_IMAGEM = "imagem";
    private static final String TAG_IMG = "imagem";
    private static String email = "";
    JSONArray podcasts = null;

    private Podcasts pdc;
    List<Podcasts> favoritos;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        meuhelper = new Helper();
        jsonParser = new JsonParser();
        sessionManager = new SessionManager(getApplicationContext());
        //sessionManager.cleanOldSession();
        sessionManager.checkLogin();

        favoritos = new ArrayList<>();
        mRecyclerView = new RecyclerView(this);

        //mLayoutManager = new LinearLayoutManager(this);
        //mRecyclerView.setLayoutManager(mLayoutManager);

        mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);

        mRecyclerView.setHasFixedSize(true);

        final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);

        MainAdapter adapter = new MainAdapter(favoritos);
        mRecyclerView.setAdapter(adapter);

        email = sessionManager.getEmail();
        Log.d("MAIN =====> ", email);
        new getFavoritos().execute(email);


        Log.d("LIFECYCLE =====>", "CREATED");
    }

    /*@Override
    protected void onStart() {
        super.onStart();
        Log.d("LIFECYCLE =====>", "STARTED");
    }*/

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("LIFECYCLE =====>", "RESUMED");
    }

    private class getFavoritos extends AsyncTask<String, String, JSONObject>{

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(MainActivity.this);
            pDialog.setMessage("Attempting login...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        @Override
        protected JSONObject doInBackground(String... args) {
            String url = meuhelper.ip + meuhelper.url_mylist;

            try {

                HashMap<String, String> params = new HashMap<>();
                params.put("email", args[0]);

                JSONObject json = jsonParser.makeHttpRequest(
                        url, "POST", params);

                if (json != null) {
                    Log.d("JSON result", json.toString());
                    try {
                        JSONObject jsonObj = new JSONObject(String.valueOf(json));
                        podcasts = jsonObj.getJSONArray(TAG_PODCASTS);

                        for (int i = 0; i < podcasts.length(); i++) {
                            JSONObject c = podcasts.getJSONObject(i);

                            //String id = c.getString(TAG_ID);
                            String nome = c.getString(TAG_NOME);
                            String autor = c.getString(TAG_AUTOR);
                            String categoria = c.getString(TAG_CATEGORIA);
                            String link = c.getString(TAG_LINK);
                            String imagem = c.getString(TAG_IMG);
                            //String descricao = c.getString(TAG_DESCRICAO);

                            Log.d("QFOI", nome);

                            Log.d("IMPOSSIVEL: ", link);

                            pdc = new Podcasts();

                            //pdc.setId();
                            pdc.setNome(nome);
                            pdc.setAutor(autor);
                            pdc.setCategoria(categoria);
                            pdc.setLink(link);
                            pdc.setImagem(imagem);

                            favoritos.add(pdc);
                        }
                    } catch (Exception e){
                        e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(JSONObject jsonObject) {
            super.onPostExecute(jsonObject);
            if (pDialog != null && pDialog.isShowing()) {
                pDialog.dismiss();
            }
        }
    }
}

我有一個啟動屏幕(活動),可以運行測試以查看用戶是否有會話。 如果沒有,它將打開LoginActivity。

我認為RecyclerView可能有問題。 我無法解決。 我希望你能幫助我。 謝謝。

編輯

SessionManager:

    public void checkLogin(){
        // Check login status
        if(!this.isLoggedIn()){
            // user is not logged in redirect him to Login Activity
            Intent i = new Intent(_context, LoginActivity.class);
            // Closing all the Activities
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            // Add new Flag to start new Activity
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            // Starting Login Activity
            _context.startActivity(i);
        } else {
            Intent i = new Intent(_context, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            _context.startActivity(i);
        }

    }

public boolean isLoggedIn(){
        return pref.getBoolean(IS_LOGGED, false);
    }
}
  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new getFavoritos().execute(email);
}

private class getFavoritos extends AsyncTask<String, String,List<Podcasts>>{

    @Override
    protected void onPreExecute() {
        dialog.show();
    }

    @Override
    protected JSONObject doInBackground(String... args) {
      //operations
        return favoritos;
    }

    @Override
    protected void onPostExecute(List<Podcasts> favoritos) {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
      if(List<Podcasts>!=null){
        showFavoritosList(List<Podcasts>)
      }
    }
}

public void showFavoritosList(List<Podcasts>){
        final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);

        MainAdapter adapter = new MainAdapter(favoritos);
        mRecyclerView.setAdapter(adapter);
}

試試這個,這可能行得通。

UPDATE

mRecyclerView = new RecyclerView(this);
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);

我在您的代碼中看到了這一行,您不需要兩次初始化回收站視圖。 當您使用findViewById您將獲得RecyclerView的對象,因此new RecyclerView(this); 不需要,在這種情況下也沒有用。

更新2

我懷疑您會在checkLogin方法中再次啟動MainActivity,這是錯誤的方法,相反,您可以直接返回布爾值。

例如:

@Override
protected void onCreate(Bundle savedInstanceState) {
              boolean isSessionExist =  sessionManager.isLoggedIn();
               if(isSessionExist){
                //open home screen
               }else{
                 //open login screen
               }
          }

isLoggedIn

    public boolean isLoggedIn(){
            return pref.getBoolean(IS_LOGGED, false);
        }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM