The Android ‘Run App’ dialog does not appear in one project but goes to another

I’m toying with Android Studio making a very simple very stupid app to learn about saving key preferences and I ran into a weird obstacle. I’ll try to provide as much as I can since it may be hard to reproduce this bug but honestly both apps I’m running are super basic and there no compile errors .

Specs: No emulator, I’m running a Samsung Galaxy Tablet . Windows 7, Android Studio 1.2, Gradle 2.2.1.

In the question title, I mean that I have a project named Kitty (pretty much hello world and a button). I click Run->’Run app’->(Dialogue box opens)->OK->Within moments the app launches on my tablet.

^^^THIS IS THE BEAUTIFUL SCREEN I WANT TO SEE ON Sharedpreferences , but it’s only on kitty .

Now I started another project called SharedPreferences (gist: two checkboxes ask you “do you like chocolate” and “do you like luigi” and you check one none or both and press save. Two textviews underneath will update to say if you like those things and even later if you reopen the app the textviews will remember Chocolate Luigi preferences). It is just a main_activity.

I don’t think I changed any settings or project preferences between the two and neither give me an error. MainActivity.java OUTDATED ORIGINAL SEE EDIT :

package gaga.sharedpreferences;

import android.content.SharedPreferences;
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.CheckBox;
import android.widget.CheckedTextView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    public final class setup extends MainActivity {
        public void setup () {
            //Nothing to see here!
        }

        // Define the File of Prefs; created if nonexistent
        public static final String PREFS_NAME = "MyPrefsFile";

        // Start up
        @Override
        public void onCreate(Bundle state) {
            super.onCreate(state);

            // Restore preferences on Startup
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            boolean Chocolate = settings.getBoolean("checkChocolate", false);
            boolean Luigi = settings.getBoolean("checkLuigi", false);
            // Function set to Whatever
            // setSilent(silent);
            /* Note:
            * CheckedTextView and CheckBox::isChecked()
            * CheckBox::setChecked()
            * */
            CheckBox checkHandleChocolate = (CheckBox) findViewById(R.id.checkChocolate);
            CheckBox checkHandleLuigi = (CheckBox) findViewById(R.id.checkLuigi);

            // What was the preference? On Start set it to the bool it left off in
            checkHandleChocolate.setChecked(Chocolate);
            checkHandleLuigi.setChecked(Luigi);

            // Change report text on Start
            TextView buttonHandleChocolate = (TextView) findViewById(R.id.chocolate);
            TextView buttonHandleLuigi = (TextView) findViewById(R.id.luigi);

            if(Chocolate)
                buttonHandleChocolate.setText("I do prefer Chocolate");
            else
                buttonHandleChocolate.setText("I do not prefer Chocolate");
            if(Luigi)
                buttonHandleLuigi.setText("I do prefer Luigi");
            else
                buttonHandleLuigi.setText("I do not prefer Luigi");

        }

        public void saveChocolate(Boolean c) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", c);
            // Commit the edits
            editor.commit();
        }
        public void saveLuigi(Boolean l) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", l);
            // Commit the edits
            editor.commit();
        }
    }

    @Override
    protected void onStop(){
        super.onStop();
        // Objects are from android.context.Context
        //Normally I'd put the edit commits here, but that's not true
    }

    // Clicks on Done
    public void userDone (View view) {
        // View is which widget
        boolean checked = ((CheckBox) view).isChecked();

        // Which checkbox was clicked
        switch(view.getId()) {
            case R.id.checkChocolate:
                setup instance1 = new setup();
                instance1.saveChocolate(checked);
                // No break; continue along
            case R.id.checkLuigi:
                setup instance2 = new setup();
                instance2.saveLuigi(checked);
                break;
        }
    }

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

    @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_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Red parts of logcat:

06-02 20:49:57.245  25557-25557/? I/SDP.PUB_CRYPTOD﹕ Starting
06-02 20:49:57.245  25557-25557/? I/SDP.PUB_CRYPTOD﹕ Socket created with fd:-1
06-02 20:49:57.245  25557-25557/? E/SDP.PUB_CRYPTOD﹕ Failed to open the netlink socket with error: Protocol not supported
06-02 20:49:57.245  25557-25557/? E/SDP.PUB_CRYPTOD﹕ Exiting
06-02 20:49:59.995    2866-3012/? V/AlarmManager﹕ waitForAlarm result :8
06-02 20:50:02.280  25633-25633/? I/SDP.PUB_CRYPTOD﹕ Starting
06-02 20:50:02.280  25633-25633/? I/SDP.PUB_CRYPTOD﹕ Socket created with fd:-1
06-02 20:50:02.280  25633-25633/? E/SDP.PUB_CRYPTOD﹕ Failed to open the netlink socket with error: Protocol not supported
06-02 20:50:02.280  25633-25633/? E/SDP.PUB_CRYPTOD﹕ Exiting

Thanks for any help. I haven’t seen this issue while prowling the internet so it might be excessively noob.

EDIT: Rewritten with the only onCreate in the larger MainActivity class

package gaga.sharedpreferences;

import android.content.SharedPreferences;
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.CheckBox;
import android.widget.CheckedTextView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    public final class setup extends MainActivity {
        public void setup () {
            //Nothing to see here!
        }

        // Define the File of Prefs; created if nonexistent
        public static final String PREFS_NAME = "MyPrefsFile";

        // Start up
        public void onCreateSubclass() {
            // super.onCreate(state);

            // Restore preferences on Startup
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            boolean Chocolate = settings.getBoolean("checkChocolate", false);
            boolean Luigi = settings.getBoolean("checkLuigi", false);
            // Function set to Whatever
            // setSilent(silent);
            /* Note:
            * CheckedTextView and CheckBox::isChecked()
            * CheckBox::setChecked()
            * */
            CheckBox checkHandleChocolate = (CheckBox) findViewById(R.id.checkChocolate);
            CheckBox checkHandleLuigi = (CheckBox) findViewById(R.id.checkLuigi);

            // What was the preference? On Start set it to the bool it left off in
            checkHandleChocolate.setChecked(Chocolate);
            checkHandleLuigi.setChecked(Luigi);

            // Change report text on Start
            TextView buttonHandleChocolate = (TextView) findViewById(R.id.chocolate);
            TextView buttonHandleLuigi = (TextView) findViewById(R.id.luigi);

            if(Chocolate)
                buttonHandleChocolate.setText("I do prefer Chocolate");
            else
                buttonHandleChocolate.setText("I do not prefer Chocolate");
            if(Luigi)
                buttonHandleLuigi.setText("I do prefer Luigi");
            else
                buttonHandleLuigi.setText("I do not prefer Luigi");

        }

        public void saveChocolate(Boolean c) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", c);
            // Commit the edits
            editor.commit();
        }
        public void saveLuigi(Boolean l) {
            // All objects from android.context.Context
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("Chocolate", l);
            // Commit the edits
            editor.commit();
        }
    }

    @Override
    protected void onStop(){
        super.onStop();
        // Objects are from android.context.Context
        //Normally I'd put the edit commits here, but that's not true
    }

    // Clicks on Done
    public void userDone (View view) {
        // View is which widget
        boolean checked = ((CheckBox) view).isChecked();

        // Which checkbox was clicked
        switch(view.getId()) {
            case R.id.checkChocolate:
                setup instance1 = new setup();
                instance1.saveChocolate(checked);
                // No break; continue along
            case R.id.checkLuigi:
                setup instance2 = new setup();
                instance2.saveLuigi(checked);
                break;
        }
    }

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

        setup startInstance = new setup();
        startInstance.onCreateSubclass();
    }

    @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_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

In Android Studio you need create a Run Configuration in your project.

Go to this link to left run icon

And click on Edit Configuration, after in the windows configure like this:

And save it, for test click run icon.

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » The Android ‘Run App’ dialog does not appear in one project but goes to another

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录