2

When I run my app it just opens a white screen and stays there, it slows my whole phone down until I'm forced to shut it down. Logcat says that the first error is "Perfoming stop of activity that is not resumed". I don't really have a onResume on my main file. Should I have a onResume or is there another way to fix this problem?

Here is the error I get when it runs:

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.access$1100(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)

Here is the code for my main 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);

    }

}

Here is the code for my Login 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();
                        }

                    }
                });
            }
        });
    }
}

Thank you for your time.

gunR
  • 45
  • 1
  • 6

1 Answers1

0

You have made action before Activity has finished loading:

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

must be on the top in Your onCreate(). Also, the logcat says, that the problem might be in the LoginActivity. Change the order like I said and come back if this was not the problem.

Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
  • Ok, I changed the order and the app crashes on startup. The error I get is "Unable to start activity ComponentInfo{com.example.douglas.topic/com.example.douglas.topic.LoginActivity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features" Should I check my themes or was that not supposed to happen? – gunR May 13 '15 at 11:40
  • here, this what You now get is another issue that has nothing to do with Your first one. See here: http://stackoverflow.com/questions/29784124/java-lang-illegalargumentexception-appcompat-does-not-support-the-current-theme – Opiatefuchs May 13 '15 at 11:45
  • hmm, I tried every solution in that thread and it didn't seem to fix the problem. I got the same error every time. – gunR May 13 '15 at 12:02
  • logcat output is : "05-13 06:34:10.119: E/AndroidRuntime(11721): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.douglas.topic/com.example.douglas.topic.Lorem}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features" – gunR May 13 '15 at 12:35
  • I think You should start a new question because this one is answered and another problem. In that qeustion You should provide the logcat and Your theme.xml.... – Opiatefuchs May 13 '15 at 13:06
  • Yeah I had the same idea, thank you for solving this question. – gunR May 13 '15 at 13:31
  • Ok I posted the question: http://stackoverflow.com/questions/30216677/android-studio-error-appcompat-does-not-support-theme – gunR May 13 '15 at 13:44