Android faolligini to'xtatish

Men internetda bu mavzu haqida o'qiganman, ammo echim topish uchun omadsizman. Manifest faylida android: noHistory = "true" qo'shish kabi mavjud echimlar men uchun ishlamadi. Istalgan narsa, foydalanuvchining tugma tugmasini (android emulyatori) chertganida foydalanuvchini selectdifficulty sahifasiga yo'naltiradigan playgame tugmasini bosgandan so'ng, u qayta mainMenu-ga qaytadi.

Bu mening ochiq faylim:

<?xml version="1.0" encoding="utf-8"?>




    
        
            
            
        
    

    
        
            
            
        
    

    
        
            
            
        
    

    
        
            
            
        
    


Bu mening asosiy faoliyatim:

package com.kfc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;

public class NewKFCActivity extends Activity {
    /** Called when the activity is first created. */
    ImageButton bPlay, bHelp;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        bPlay = (ImageButton) findViewById(R.id.playGame);
        bPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               //TODO Auto-generated method stub
                Intent intent = new Intent(v.getContext(), SelectDifficulty.class);
                startActivityForResult(intent,0);
                finish();
            }
        });

        bHelp = (ImageButton) findViewById(R.id.Help);
        bHelp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               //TODO Auto-generated method stub
                Intent intent = new Intent(v.getContext(), HelpPageOne.class);
                startActivityForResult(intent,0);
                finish();
            }
        });


    }
    @Override
    protected void onPause() {
       //TODO Auto-generated method stub
        super.onPause();
        finish();
    }
}

Bu mening qiyinchiliklarim sinfidir:

package com.kfc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

public class SelectDifficulty extends Activity{
    ImageButton bEasy, bMedium, bHard;
    @Override
    protected void onCreate(Bundle kfcState) {
       //TODO Auto-generated method stub
        super.onCreate(kfcState);
        setContentView(R.layout.difficultyxml);

        bEasy = (ImageButton) findViewById(R.id.easy);
        bEasy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               //TODO Auto-generated method stub
                //Intent intent = new Intent(v.getContext(), NewKFCActivity.class);
                //startActivityForResult(intent,0);
            }
        });
    }

}
2
nima uchun finish() ni saqlaysiz? NewKFCActivity ilovasida
qo'shib qo'ydi muallif Sherif elKhatib, manba
Sizning savolingiz nima?
qo'shib qo'ydi muallif Glenn85, manba
Lekin siz startActivityForResult (niyat, 0); dan foydalanmoqdasiz, shuning uchun faoliyat turishi kerak, aks holda natijani hech qachon qayta ishlamaydi.
qo'shib qo'ydi muallif Glenn85, manba
foydalanuvchi qiyinchilik sahifasida Android telefonidagi Orqaga tugmachasini bosganda, u yana asosiy menyuga qaytadi. Asosiy menyuda playGame tugmasi mavjud va foydalanuvchini qiyinchilik sahifasiga yo'naltiradi. Kodlar ichida ko'rib turganingizdek, uni tugatish() da ishlay olmaysiz
qo'shib qo'ydi muallif Bennett Young, manba
@ Sherif: afsus, men sizning savolingizni tushunmayapman. faqat Android kunlar oldin rivojlana boshladi, shuning uchun iltimos, menga ayin .. thanks :)
qo'shib qo'ydi muallif Bennett Young, manba
OK .. OK ... shuni tuzatishga yordam bera olasizmi? nima qilishim kerak?
qo'shib qo'ydi muallif Bennett Young, manba

2 javoblar

Avvalo startActivity() va startActivityForResult() o'rtasidagi farqni bilishingiz kerak, qarang: Android ishlab chiquvchilari veb-sayti .

Ikkinchidan, Faoliyatning hayot aylanishini tushunishingiz kerak. > Siz uni qoldirganingizdan so'ng, har bir harakatni finish() shart emas, Android siz uchun bu narsani boshqaradi.

Umid qilamanki :) Cheers!

3
qo'shib qo'ydi
oh i ko'rayapman .. rahmat!
qo'shib qo'ydi muallif Bennett Young, manba

Qatorlarni olib tashlang:

finish();

keyin

startActivityForResult(...);

Activity Activity NewKFCA faolligi amalda sizning harakatingizni buzadi va orqaga qaytsangiz, yana qaytib boradigan faoliyat yo'q!

0
qo'shib qo'ydi