线程无效...... [英] Threading is not working....

查看:84
本文介绍了线程无效......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个简单的线程无法正常工作找不到错误帮助请...

i希望显示我的splash.xml 6秒然后再显示activity_main.xml但它没有显示activity_main。 xml ......



我尝试过:



我的splash.java代码:

this simple threading is not working cann't find the errors help please...
i want to show my splash.xml for 6 sec and then activity_main.xml but it not showing the activity_main.xml ......

What I have tried:

my splash.java code:

package com.example.ne;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class splash extends Activity{
	
	 protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.splash);
	        Thread timer = new Thread()
	        {
	        	public void run(){
	        		try{
	        			sleep(6000);
	        			
	        			
	        		} catch(InterruptedException e){
	        			e.printStackTrace();
	        			
	        		}finally{
	        			Intent open =new Intent("com.example.ne.MAINACTIVITY");
	        			startActivity(open);
	        		}
	        	}
	        };
	        timer.start();
	        
	 }
	

}









和mainactivity.java代码:





and mainactivity.java code:

package com.example.ne;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	
	int counter;
	Button add,sub;
	TextView display;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        counter=0;
        add=(Button) findViewById(R.id.bAdd);
        sub=(Button)findViewById(R.id.bSub);
        display=(TextView)findViewById(R.id.tvdisplay);
        add.setOnClickListener(new View.OnClickListener() {
			
			@Override
			
			public void onClick(View arg0) {
				counter++;
				// TODO Auto-generated method stub
				display.setText("Your total is" + counter);
				
			}
		});
sub.setOnClickListener(new View.OnClickListener() {
			
			@Override
			
			public void onClick(View arg0) {
				counter--;
				display.setText("Your total is" + counter);
				// TODO Auto-generated method stub
				
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
}







和manifest.xml代码:





< manifest xmlns:android =http://schemas.android.com/apk/res/android> ;

package =com.example.ne

android:versionCode =1

android:versionName =1.0>



< uses-sdk>

android:minSdkVersion =8

android:targetSdkVersion = 17/>



< application>

android:allowBackup =true

android: icon =@ drawable / ic_launcher

android:label =@ string / app_name

android:theme =@ style / AppTheme>

< activity>

android:name =com.example.ne.splash

android:label =@ string / app_name>

< intent-filter>

< action android:name =android.intent.a ction.MAIN>



< category android:name =android.intent.category.LAUNCHER>







< application>

android:allowBackup =true

android :icon =@ drawable / ic_launcher

android:label =@ string / app_name

android:theme =@ style / AppTheme>

< activity>

android:name =。MainActivityandroid:label =@ string / app_name>

< intent-filter> ;

< action android:name =com.example.ne.MAINACTIVITY>



< category android:name = android.intent.category.DEFAULT>











and manifest.xml code:


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="com.example.ne"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk>
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application>
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity>
android:name="com.example.ne.splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN">

<category android:name="android.intent.category.LAUNCHER">



<application>
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity>
android:name=".MainActivity" android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.ne.MAINACTIVITY">

<category android:name="android.intent.category.DEFAULT">




推荐答案

我和谢尔盖在这个问题上你需要自己解决这个问题,所以你明白了。 />


停止抨击代码并坐下来拿一张纸并写下该oncreate中发生的事情的顺序。



当你开始编写线程时,你需要查看你所要求的序列而不是代码。
I am with Sergey on this one and you need to fix this yourself, so you understand.

Stop just bashing code and sit and get a piece of paper and write the sequence of what happens in that oncreate.

When you start writing threads you need to sometimes look at the sequence you have asked for NOT THE CODE.


这篇关于线程无效......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆