java - xml (activity) stays open in the back ground when it should close -
i making quiz android app using eclipse , made every question has own activity, works ok if answer qustions slow if faster xml stays open in background added onpause
method still open. not know how use threads told me make app faster xml close. hope there easy fix problem if not, can explain me how use threads.
here 1 of xml layouts:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/qh4" tools:context=".pov6" > <textview android:id="@+id/povrat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_marginbottom="150dp" android:layout_margintop="50dp" android:paddingleft="@dimen/activity_vertical_margin" android:paddingright="@dimen/activity_vertical_margin" android:text="the highest peak in north america ?" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#000000" android:textstyle="bold" tools:ignore="hardcodedtext" /> <button android:id="@+id/button2" android:layout_width="175dp" android:layout_height="wrap_content" android:layout_below="@+id/povrat" android:layout_centerhorizontal="true" android:onclick="tocan" android:text="mount mckinley" tools:ignore="hardcodedtext" /> <button android:id="@+id/button3" android:layout_width="175dp" android:layout_height="wrap_content" android:layout_alignleft="@+id/button2" android:layout_below="@+id/button2" android:onclick="netocanodgovor" android:text="mount everest" tools:ignore="hardcodedtext" /> <button android:id="@+id/button4" android:layout_width="175dp" android:layout_height="wrap_content" android:layout_alignright="@+id/button3" android:layout_below="@+id/button3" android:onclick="netocanodgovor" android:text="mount logan" tools:ignore="hardcodedtext" /> <button android:id="@+id/button5" android:layout_width="175dp" android:layout_height="wrap_content" android:layout_alignleft="@+id/button4" android:layout_below="@+id/button4" android:onclick="netocanodgovor" android:text="mount rainier" tools:ignore="hardcodedtext" /> <slidingdrawer android:id="@+id/slidingdrawer1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:content="@+id/content" android:handle="@+id/handle" > <button android:id="@+id/handle" style="?android:attr/buttonstylesmall" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="pull use jokers !" tools:ignore="hardcodedtext" /> <linearlayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:baselinealigned="false" > <tabhost android:id="@+id/tabhost" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" > </tabwidget> <framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <relativelayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" > <textview android:id="@+id/rekord" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="50dp" android:paddingbottom="20dp" android:text="this joker remowes 1 wrong answer !" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <textview android:id="@+id/joker1text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@id/rekord" android:layout_marginleft="10dp" android:text="medium text" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <button android:id="@+id/button6" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:onclick="joker1" android:text="use joker !" tools:ignore="hardcodedtext" /> </relativelayout> <relativelayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" > <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="50dp" android:paddingbottom="20dp" android:text="this joker give right answer (30% of cases) ! " android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <textview android:id="@+id/joker2text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@id/textview3" android:layout_marginleft="10dp" android:text="medium text" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <textview android:id="@+id/joker2odgovor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/joker2text" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="50dp" android:text="i think right answer mount mckinley " android:textappearance="?android:attr/textappearancemedium" android:textstyle="bold" android:visibility="invisible" tools:ignore="hardcodedtext" /> <button android:id="@+id/button8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:onclick="joker2" android:text="use joker !" tools:ignore="hardcodedtext" /> </relativelayout> <relativelayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" > <textview android:id="@+id/textview4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="50dp" android:paddingbottom="20dp" android:text="this joker skip question. no points !" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <textview android:id="@+id/joker3text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@id/textview4" android:layout_marginleft="10dp" android:text="medium text" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <button android:id="@+id/button10" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:onclick="joker3" android:text="use joker !" tools:ignore="hardcodedtext" /> </relativelayout> <relativelayout android:id="@+id/tab4" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" > <textview android:id="@+id/textview5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="50dp" android:paddingbottom="20dp" android:text="this joker give right answer !" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <textview android:id="@+id/joker4text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@id/textview5" android:layout_marginleft="10dp" android:text="medium text" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" tools:ignore="hardcodedtext" /> <button android:id="@+id/button12" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:onclick="joker4" android:text="use joker !" tools:ignore="hardcodedtext" /> </relativelayout> </framelayout> </linearlayout> </tabhost> </linearlayout> </slidingdrawer> </relativelayout>
here java code:
package com.peky.smartornot; import java.util.random; import android.os.bundle; import android.app.activity; import android.content.intent; import android.view.view; import android.widget.button; import android.widget.tabhost; import android.widget.textview; import android.widget.toast; import android.widget.tabhost.tabspec; public class pov6 extends activity { sql ulaz = new sql(this); sqlrecords rekordi = new sqlrecords(this); textview joke4text; textview joke3text; textview joke2text; textview joke1text; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_pov6); sve(); } public void sve() { // todo auto-generated method stub ulaz.open(); int joker1 = ulaz.procitaj(), joker2 = ulaz.procitaj2(), joker3 = ulaz .procitaj3(), joker4 = ulaz.procitaj4(); ulaz.close(); tabhost joker = (tabhost) findviewbyid(r.id.tabhost); joker.setup(); tabspec izgled = joker.newtabspec("tag1"); izgled.setcontent(r.id.tab1); izgled.setindicator("joker 1"); joker.addtab(izgled); izgled = joker.newtabspec("tag2"); izgled.setcontent(r.id.tab2); izgled.setindicator("joker 2"); joker.addtab(izgled); izgled = joker.newtabspec("tag3"); izgled.setcontent(r.id.tab3); izgled.setindicator("joker 3"); joker.addtab(izgled); izgled = joker.newtabspec("tag4"); izgled.setcontent(r.id.tab4); izgled.setindicator("joker 4"); joker.addtab(izgled); joke1text = (textview) findviewbyid(r.id.joker1text); joke1text.settext("you have " + joker1 + " jokers !"); joke2text = (textview) findviewbyid(r.id.joker2text); joke2text.settext("you have " + joker2 + " jokers !"); joke3text = (textview) findviewbyid(r.id.joker3text); joke3text.settext("you have " + joker3 + " jokers !"); joke4text = (textview) findviewbyid(r.id.joker4text); joke4text.settext("you have " + joker4 + " jokers !"); } public void joker1(view view) { button netocan = (button) findviewbyid(r.id.button5); button netocan2 = (button) findviewbyid(r.id.button4); button netocan3 = (button) findviewbyid(r.id.button3); ulaz.open(); int joker1 = ulaz.procitaj(), joker2, joker3, joker4; ulaz.close(); if (joker1 != 0) { if (netocan.getvisibility() == view.visible) { netocan.setvisibility(view.invisible); ulaz.open(); joker1 = joker1 - 1; joker2 = ulaz.procitaj2(); joker3 = ulaz.procitaj3(); joker4 = ulaz.procitaj4(); ulaz.spremijoker(joker1, joker2, joker3, joker4); ulaz.close(); joke1text = (textview) findviewbyid(r.id.joker1text); joke1text.settext("you have " + joker1 + " jokers !"); } else if (netocan2.getvisibility() == view.visible) { netocan2.setvisibility(view.invisible); ulaz.open(); joker1 = joker1 - 1; joker2 = ulaz.procitaj2(); joker3 = ulaz.procitaj3(); joker4 = ulaz.procitaj4(); ulaz.spremijoker(joker1, joker2, joker3, joker4); ulaz.close(); joke1text = (textview) findviewbyid(r.id.joker1text); joke1text.settext("you have " + joker1 + " jokers !"); } else if (netocan3.getvisibility() == view.visible) { netocan3.setvisibility(view.invisible); ulaz.open(); joker1 = joker1 - 1; joker2 = ulaz.procitaj2(); joker3 = ulaz.procitaj3(); joker4 = ulaz.procitaj4(); ulaz.spremijoker(joker1, joker2, joker3, joker4); ulaz.close(); joke1text = (textview) findviewbyid(r.id.joker1text); joke1text.settext("you have " + joker1 + " jokers !"); } else { toast imasodgovor = toast.maketext(getapplicationcontext(), "you can not use more jokers1 on question !", toast.length_short); imasodgovor.show(); } } else { toast nemasjokera = toast.maketext(getapplicationcontext(), "not enought jokers1 !", toast.length_short); nemasjokera.show(); } } public void joker4(view view) { ulaz.open(); int joker1, joker2, joker3, joker4 = ulaz.procitaj4(); ulaz.close(); button netocan = (button) findviewbyid(r.id.button5); button netocan2 = (button) findviewbyid(r.id.button4); button netocan3 = (button) findviewbyid(r.id.button3); if (joker4 != 0) { if (netocan.getvisibility() == view.visible || netocan2.getvisibility() == view.visible || netocan3.getvisibility() == view.visible) { netocan.setvisibility(view.invisible); netocan2.setvisibility(view.invisible); netocan3.setvisibility(view.invisible); ulaz.open(); joker1 = ulaz.procitaj(); joker2 = ulaz.procitaj2(); joker3 = ulaz.procitaj3(); joker4 = joker4 - 1; ; ulaz.spremijoker(joker1, joker2, joker3, joker4); ulaz.close(); joke4text = (textview) findviewbyid(r.id.joker4text); joke4text.settext("you have " + joker4 + " jokers !"); } else { toast imasodgovor = toast.maketext(getapplicationcontext(), "you can not use more jokers4 on question !", toast.length_short); imasodgovor.show(); } } else { toast jokertext = toast.maketext(getapplicationcontext(), "not enought jokers4", toast.length_short); jokertext.show(); } } public void joker3(view view) { ulaz.open(); int joker3 = ulaz.procitaj3(), joker1, joker2, joker4; ulaz.close(); if (joker3 != 0) { ulaz.open(); joker1 = ulaz.procitaj(); joker2 = ulaz.procitaj2(); joker4 = ulaz.procitaj4(); joker3 = joker3 - 1; ulaz.spremijoker(joker1, joker2, joker3, joker4); ulaz.close(); random crazy = new random(); switch (crazy.nextint(4)) { case 0: intent pokreni = new intent(this, pov3.class); startactivity(pokreni); finish(); break; case 1: intent pokreni1 = new intent(this, pov1.class); startactivity(pokreni1); finish(); break; case 2: intent pokreni11 = new intent(this, pov4.class); startactivity(pokreni11); finish(); break; case 3: intent pokreni111 = new intent(this, pov5.class); startactivity(pokreni111); break; } } } public void joker2(view view) { textview joker2odgovor = (textview) findviewbyid(r.id.joker2odgovor); ulaz.open(); int joker1, joker2 = ulaz.procitaj2(), joker3, joker4; ulaz.close(); if (joker2 != 0 && joker2odgovor.getvisibility() == view.invisible) { ulaz.open(); joker1 = ulaz.procitaj(); joker2 = joker2 - 1; joker3 = ulaz.procitaj3(); joker4 = ulaz.procitaj4(); ulaz.spremijoker(joker1, joker2, joker3, joker4); ulaz.close(); joker2odgovor.setvisibility(view.visible); joke2text = (textview) findviewbyid(r.id.joker2text); joke2text.settext("you have " + joker2 + " jokers !"); } else { toast odgovor = toast.maketext(getapplicationcontext(), "not enought jokers2 or used on question !", toast.length_short); odgovor.show(); } } public void tocan(view view) { toast josip = toast.maketext(getapplicationcontext(), "right answer !", toast.length_short); josip.show(); int rekord = 0, ukupno = 0; rekordi.open(); ukupno = rekordi.procitajukupno(); rekord = rekordi.procitaj() + 10; rekordi.spremi(rekord, ukupno); rekordi.close(); random crazy = new random(); switch (crazy.nextint(4)) { case 0: intent pokreni = new intent(this, pov3.class); startactivity(pokreni); finish(); break; case 1: intent pokreni1 = new intent(this, pov1.class); startactivity(pokreni1); finish(); break; case 2: intent pokreni11 = new intent(this, pov4.class); startactivity(pokreni11); finish(); break; case 3: intent pokreni111 = new intent(this, pov5.class); startactivity(pokreni111); break; } } public void netocanodgovor(view view) { intent gotovo = new intent(this, records.class); startactivity(gotovo); finish(); toast josip = toast.maketext(getapplicationcontext(), "incorrect answer !", toast.length_short); josip.show(); } @override protected void onpause() { // todo auto-generated method stub super.onpause(); finish(); } }
if need more information, or whole app can send !
Comments
Post a Comment