Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
Java
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();
	        
	 }
	

}




and mainactivity.java code:
Java
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;
    }
    
}



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">




Posted
Updated 1-May-16 17:13pm
Comments
Richard MacCutchan 14-Mar-16 9:54am    
where do you start the splash activity?
Sergey Alexandrovich Kryukov 14-Mar-16 23:04pm    
What would you expect from a thread code which does nothing, just waits? Why do you use a timer and a thread at the same time; what's the purpose? In all cases, "not working" is not informative. Chances are, you just need a timer, to close the splash screen and go ahead...
—SA

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900