Android的活动startactivity

Android的活动startactivity

本文介绍了Android的活动startactivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开这一个(KlikomaniaActivity)通过按钮另一活动(GameProcess),但是当我点击该按钮的程序崩溃。我不一个业余体校的Andr​​oid程序员,请说我有什么错误:

  packagecom.makeandroid.klikomania;
进口android.os.Bundle;
进口android.app.Activity;
进口android.content.Intent;
进口android.view.Menu;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;


公共类KlikomaniaActivity延伸活动{

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    最终按钮Butstart =(按钮)findViewById(R.id.butstart);
    最终按钮Butrez =(按钮)findViewById(R.id.butrez);

    Butstart.setOnClickListener(新View.OnClickListener(){
        公共无效的onClick(视图v){
            意向意图=新的意图(com.makeandroid.klikomania.GameProcess);
             //эапускаемдеятельнсть
             startService(意向);
        }
    });
}

}
 

在这里GameProcess Acticity:

 公共类GameProcess扩展KlikomaniaActivity {

私有静态诠释rezult = 0;
 @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.gameprocess);

        最终按钮Butklik =(按钮)findViewById(R.id.klik);
        最后的TextView TextTime =(TextView中)findViewById(R.id.texttime);
        最后的TextView TextKolvo =(TextView中)findViewById(R.id.kolvo);

        Butklik.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
            rezult = rezult + 1;
            TextKolvo.setText(rezult);
            }
        });
 }
}
 

解决方案

首先确保您添加您的活动清单文件:

 <活动机器人:名称=com.makeandroid.klikomania.GameProcess>< /活性GT;
 

第二,启动活动中使用这种code:

 最终意图gameProcessIntent =新的意图(这一点,GameProcess.class);
Butstart.setOnClickListener(新View.OnClickListener(){
    公共无效的onClick(视图v){
        startActivity(gameProcessIntent);
    }
});
 

这应该工作normaly

i want to open another Activity(GameProcess) from this one (KlikomaniaActivity) through button, but when i tap the button the program crashes. i don't a proffesional android programmer, please say what mistakes i have:

packagecom.makeandroid.klikomania;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class KlikomaniaActivity extends Activity {

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

    final Button Butstart = (Button)findViewById(R.id.butstart);
    final Button Butrez = (Button)findViewById(R.id.butrez);

    Butstart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent("com.makeandroid.klikomania.GameProcess");
             // эапускаем деятельнсть
             startService(intent);
        }
    });
}

}

and here GameProcess Acticity:

public class GameProcess extends KlikomaniaActivity {

private static int rezult = 0;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gameprocess);

        final Button Butklik = (Button)findViewById(R.id.klik);
        final TextView TextTime = (TextView)findViewById(R.id.texttime);
        final TextView TextKolvo = (TextView)findViewById(R.id.kolvo);

        Butklik.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            rezult=rezult+1;
            TextKolvo.setText(rezult);
            }
        });
 }
}
解决方案

First make sure that you added your activity to the manifest file :

<activity android:name="com.makeandroid.klikomania.GameProcess"></activity>

second, to start the activity use this code:

final Intent gameProcessIntent= new Intent(this, GameProcess.class);
Butstart.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        startActivity(gameProcessIntent);
    }
});

this should work normaly

这篇关于Android的活动startactivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:04