java - Android Studio 'Run app' dialogue doesn't appear in one project but will in another -
i'm toying android studio making simple stupid app learn saving key preferences , ran weird obstacle. i'll try provide as can since may hard reproduce bug both apps i'm running super basic , there no compile errors.
specs: no emulator, i'm running samsung galaxy tablet. windows 7, android studio 1.2, gradle 2.2.1.
in question title, mean have project named kitty (pretty hello world , button). click run->'run app'->(dialogue box opens)->ok->within moments app launches on tablet.
^^^this beautiful screen want see on sharedpreferences, it's on kitty.
now started project called sharedpreferences (gist: 2 checkboxes ask "do chocolate" , "do luigi" , check 1 none or both , press save. 2 textviews underneath update if things , later if reopen app textviews remember chocolate luigi preferences). main_activity.
i don't think changed settings or project preferences between 2 , neither give me 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 see here! } // define file of prefs; created if nonexistent public static final string prefs_name = "myprefsfile"; // start @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 whatever // setsilent(silent); /* note: * checkedtextview , checkbox::ischecked() * checkbox::setchecked() * */ checkbox checkhandlechocolate = (checkbox) findviewbyid(r.id.checkchocolate); checkbox checkhandleluigi = (checkbox) findviewbyid(r.id.checkluigi); // preference? on start set bool 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 prefer chocolate"); else buttonhandlechocolate.settext("i not prefer chocolate"); if(luigi) buttonhandleluigi.settext("i prefer luigi"); else buttonhandleluigi.settext("i not prefer luigi"); } public void savechocolate(boolean c) { // objects android.context.context sharedpreferences settings = getsharedpreferences(prefs_name, 0); sharedpreferences.editor editor = settings.edit(); editor.putboolean("chocolate", c); // commit edits editor.commit(); } public void saveluigi(boolean l) { // objects android.context.context sharedpreferences settings = getsharedpreferences(prefs_name, 0); sharedpreferences.editor editor = settings.edit(); editor.putboolean("chocolate", l); // commit edits editor.commit(); } } @override protected void onstop(){ super.onstop(); // objects android.context.context //normally i'd put edit commits here, that's not true } // clicks on done public void userdone (view view) { // view widget boolean checked = ((checkbox) view).ischecked(); // checkbox 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 menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify 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 fd:-1 06-02 20:49:57.245 25557-25557/? e/sdp.pub_cryptod﹕ failed open netlink socket 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 fd:-1 06-02 20:50:02.280 25633-25633/? e/sdp.pub_cryptod﹕ failed open netlink socket error: protocol not supported 06-02 20:50:02.280 25633-25633/? e/sdp.pub_cryptod﹕ exiting
thanks help. haven't seen issue while prowling internet might excessively noob.
edit: rewritten oncreate in 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 see here! } // define file of prefs; created if nonexistent public static final string prefs_name = "myprefsfile"; // start 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 whatever // setsilent(silent); /* note: * checkedtextview , checkbox::ischecked() * checkbox::setchecked() * */ checkbox checkhandlechocolate = (checkbox) findviewbyid(r.id.checkchocolate); checkbox checkhandleluigi = (checkbox) findviewbyid(r.id.checkluigi); // preference? on start set bool 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 prefer chocolate"); else buttonhandlechocolate.settext("i not prefer chocolate"); if(luigi) buttonhandleluigi.settext("i prefer luigi"); else buttonhandleluigi.settext("i not prefer luigi"); } public void savechocolate(boolean c) { // objects android.context.context sharedpreferences settings = getsharedpreferences(prefs_name, 0); sharedpreferences.editor editor = settings.edit(); editor.putboolean("chocolate", c); // commit edits editor.commit(); } public void saveluigi(boolean l) { // objects android.context.context sharedpreferences settings = getsharedpreferences(prefs_name, 0); sharedpreferences.editor editor = settings.edit(); editor.putboolean("chocolate", l); // commit edits editor.commit(); } } @override protected void onstop(){ super.onstop(); // objects android.context.context //normally i'd put edit commits here, that's not true } // clicks on done public void userdone (view view) { // view widget boolean checked = ((checkbox) view).ischecked(); // checkbox 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 menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify 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 need create run configuration in project.
go link left run icon
and click on edit configuration, after in windows configure this:
and save it, test click run icon.
Comments
Post a Comment