Android 工作室错误 "Perfoming stop of activity that is not resumed"

Android Studio Error "Perfoming stop of activity that is not resumed"

当我 运行 我的应用程序只是打开一个白屏并停留在那里时,它会减慢我的整个 phone 速度,直到我被迫将其关闭。 Logcat 表示第一个错误是 "Perfoming stop of activity that is not resumed"。我的主文件上真的没有 onResume。我应该有一个 onResume 还是有其他方法来解决这个问题?

这是我在 运行s:

时得到的错误
05-13 05:13:34.124: E/ActivityThread(27498): Performing stop of activity that is not resumed: {com.example.douglas.topic/com.example.douglas.topic.LoginActivity}
05-13 05:13:34.124: E/ActivityThread(27498): java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.example.douglas.topic/com.example.douglas.topic.LoginActivity}
05-13 05:13:34.124: E/ActivityThread(27498):    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3214)
05-13 05:13:34.124: E/ActivityThread(27498):    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3301)
05-13 05:13:34.124: E/ActivityThread(27498):    at android.app.ActivityThread.access00(ActivityThread.java:139)
05-13 05:13:34.124: E/ActivityThread(27498):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-13 05:13:34.124: E/ActivityThread(27498):    at android.os.Handler.dispatchMessage(Handler.java:102)
05-13 05:13:34.124: E/ActivityThread(27498):    at android.os.Looper.loop(Looper.java:136)
05-13 05:13:34.124: E/ActivityThread(27498):    at android.app.ActivityThread.main(ActivityThread.java:5097)
05-13 05:13:34.124: E/ActivityThread(27498):    at java.lang.reflect.Method.invokeNative(Native Method)
05-13 05:13:34.124: E/ActivityThread(27498):    at java.lang.reflect.Method.invoke(Method.java:515)
05-13 05:13:34.124: E/ActivityThread(27498):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
05-13 05:13:34.124: E/ActivityThread(27498):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
05-13 05:13:34.124: E/ActivityThread(27498):    at dalvik.system.NativeStart.main(Native Method)

这是我的主要代码 activity:

package com.example.douglas.topic;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.douglas.topic.LoginActivity;
import com.example.douglas.topic.PostActivity;
import com.example.douglas.topic.PostAdapter;
import com.example.douglas.topic.PostDataProvider;
import com.example.douglas.topic.R;
import com.parse.Parse;
import com.parse.ParseObject;
import com.parse.ParseUser;


public class Lorem extends ActionBarActivity {

    //private static final String="POST";
    ListView listView;
    int[] pic_thumbnail_resource = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher,
            R.mipmap.ic_launcher, R.mipmap.ic_launcher,};
    String[] post_ratings;
    String[] post_titles;
    PostAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Parse

        // Enable Local Datastore.
        //Parse.enableLocalDatastore(this);
        Parse.initialize(getApplicationContext(), "wHN7DSZyAzVXT5xs5ASDFGwOWasUExbeuePvQvL", "SsvjuJ7e97FsScI12VB7dlv8RilgSoFSw5waIOXM");
        //ParseObject testObject = new ParseObject("TestObject");
        //testObject.put("foo", "bar");
        //testObject.saveInBackground();

        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser != null) {
            // do stuff with the user


        } else {
            // show the signup or login screen
            Intent takeUsertoLogin = new Intent(this, LoginActivity.class);
            startActivity(takeUsertoLogin);
        }

        // End Parse

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lorem);

        listView = (ListView)findViewById(R.id.list_view);
        post_ratings = getResources().getStringArray(R.array.post_ratings);
        post_titles = getResources().getStringArray(R.array.post_titles);

        //populateListView();
        registerClickCallback();

        int i = 0;
        adapter = new PostAdapter(getApplicationContext(),R.layout.row_layout);
        listView.setAdapter(adapter);

        for(String titles: post_titles)
        {
            PostDataProvider dataProvider = new PostDataProvider(pic_thumbnail_resource[i], titles, post_ratings[i]);
            adapter.add(dataProvider);
            i++;
        }
    }


    private void registerClickCallback(){
        ListView list = (ListView) findViewById(R.id.list_view);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id){
                TextView textView = (TextView) viewClicked;
                String message = "You clicked # " + position + ",which is string: " + textView.getText().toString();
                Toast.makeText(Lorem.this, message, Toast.LENGTH_LONG).show();
            }
        });
    }

/*
    @Override
    public void onActivityResult(String requestCode, String resultCode, Intent data){

        if (requestCode == "POST")
        {
            myItems.add
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
*/

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_lorem, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        switch (item.getItemId()){
            case R.id.post:
                aboutItemPost();
                break;
            case R.id.location:
                aboutItemLocation();
                break;
            case R.id.topic:
                aboutItemTopic();
                break;
            case R.id.sort:
                aboutItemSort();
                break;
            case R.id.login:
                aboutItemLogin();
            case R.id.Register:
                aboutItemRegister();
            case R.id.Logout:
                aboutItemLogout();
        }
        return true;
    }

    private void aboutItemPost(){
        Intent intent = new Intent(getApplicationContext(), PostActivity.class);
        startActivityForResult(intent, 0);
    }

    private void aboutItemLocation(){
        Intent intent = new Intent(getApplicationContext(), LocationActivity.class);
        startActivityForResult(intent, 0);
    }

    private void aboutItemTopic(){
        Intent intent = new Intent(getApplicationContext(), TopicActivity.class);
        startActivityForResult(intent, 0);

    }

    private void aboutItemSort(){
        new AlertDialog.Builder(this)
                .setTitle("Sort")
                .setMessage("This is where the user will sort what they want to see")
                .setNeutralButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }).show();

    }

    private void aboutItemLogin(){
        Intent takeUsertoLogin = new Intent(this, LoginActivity.class);
        startActivity(takeUsertoLogin);
    }

    private void aboutItemRegister(){
        Intent intent = new Intent(getApplicationContext(), RegisterActivity.class);
        startActivityForResult(intent, 0);
    }

    private void aboutItemLogout() {
        // log the user out
        ParseUser.logOut();

        // take the user back to log in screen
        Intent takeUsertoLogin = new Intent(this, LoginActivity.class);
        startActivity(takeUsertoLogin);

    }

}

这是我的登录代码 activity:

package com.example.douglas.topic;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.parse.LogInCallback;
import com.parse.Parse;
import com.parse.ParseUser;

import java.text.ParseException;

/**
 * Created by Douglas on 5/10/2015.
 */
public class LoginActivity extends Lorem {

    protected EditText mUsername;
    protected EditText mPassword;
    protected Button mLoginButton;
    protected Button mCreateAccountButton;

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        //initialize
        mUsername = (EditText)findViewById(R.id.LoginUserName);
        mPassword = (EditText)findViewById(R.id.LoginPassword);
        mLoginButton = (Button)findViewById(R.id.LoginButton);
        mCreateAccountButton = (Button)findViewById(R.id.LoginRegisterButton);

        // Listen to when mLoginButton is clicked
        mLoginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // get the user input from the edit text and convert into string
                String username = mUsername.getText().toString().trim();
                String password = mPassword.getText().toString().trim();

                // Login the user using Parse SDK
                ParseUser.logInInBackground(username, password, new LogInCallback() {
                    @Override
                    public void done(ParseUser parseUser, com.parse.ParseException e) {

                        if (e == null) {
                            // Success, user logged in
                            Toast.makeText(LoginActivity.this, "Welcome Back!", Toast.LENGTH_SHORT).show();

                            Intent takeUserHome = new Intent(LoginActivity.this, Lorem.class);
                            startActivity(takeUserHome);

                        } else {
                            // Failure to Log in, advise user
                            AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                            builder.setMessage(e.getMessage());
                            builder.setTitle("Sorry!");
                            builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    // close the dialog window
                                    dialog.dismiss();
                                }
                            });
                            AlertDialog dialog = builder.create();
                            dialog.show();
                        }

                    }
                });
            }
        });
    }
}

感谢您的宝贵时间。

您在 Activity 完成加载之前进行了操作:

     super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lorem);

必须在您的 onCreate() 中位于顶部。此外,logcat 表示,问题可能出在登录Activity 中。像我说的那样更改顺序,如果这不是问题,请回来。