Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualNUCLEAR RABBIT

Posted 07 April 2013 - 01:59 PM

Hello, So I am trying to put an activity that displays a picture in the beginning of my app for 2 seconds and then goes to another activity where the user tries to guess the computers number. The MainActivity works fine, Problem is, when I add the new activity (splash) to the manifest file, and change the splash activity as the launcher and the main activity to default for the intent category, it doesnt run anymore! Can someone pleeease help me understand what I am doing wrong...

 

MainActivity.java

package com.bwall.thenumbergame;

import java.util.Random;

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

public class MainActivity extends Activity {
	
	// global variables
	int number, compNumber;
	EditText textField;
	TextView result, gameObjective;
	Button button;
	Random rand = new Random(System.nanoTime());
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		// setting views
		textField = (EditText) findViewById(R.id.textField);
		result = (TextView) findViewById(R.id.resultView);
		gameObjective = (TextView) findViewById(R.id.gameObjective);
		button = (Button) findViewById(R.id.submitButton);
		
		// creating computer number
		compNumber = rand.nextInt(10);
		    
		button.setOnClickListener(new View.OnClickListener() {
				
			@Override
			public void onClick(View v) {
				number = Integer.parseInt(textField.getText().toString());
					
				// checks if correct guess
				if(number == compNumber) {
					result.setText("CORRECT! The nummber was " + compNumber);
				} else {
					result.setText("LOL nope. Guess Again.");
				}
			}
		});
	}
}

 

Splash.java

package com.bwall.thenumbergame;

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

public class Splash extends Activity {
	
	final Context context = this;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		
		Thread timer = new Thread() {
			public void run() {
				
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} finally {
					Intent mainIntent = new Intent(context, MainActivity.class);
					startActivity(mainIntent);
				}
			}
		};
		timer.start();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}
}

 

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splashbackground"
    android:orientation="vertical" >

</LinearLayout>

 

activity_main.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/gameObjective"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="@string/gameObjective"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/textField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/gameObjective"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:inputType="number" />

    <requestFocus />

    <Button
        android:id="@+id/submitButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textField"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="19dp"
        android:text="@string/submitButton" />

    <TextView
        android:id="@+id/resultView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/submitButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="58dp"
        android:textIsSelectable="true" />

</RelativeLayout>

 

TheNumberGame Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bwall.thenumbergame"
    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.bwall.thenumbergame.Splash"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="com.bwall.thenumbergame.SPLASH" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.bwall.thenumbergame.MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

#2NUCLEAR RABBIT

Posted 07 April 2013 - 01:54 PM

Hello, So I am trying to put an activity that displays a picture in the beginning of my app for 2 seconds and then goes to another activity where the user tries to guess the computers number. Problem is, when I add the new activity (splash) to the manifest file, and change the splash activity as the launcher and the main activity to default it doesnt run anymore! Can someone pleeease help me understand what I am doing wrong...

 

MainActivity.java

package com.bwall.thenumbergame;

import java.util.Random;

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

public class MainActivity extends Activity {
	
	// global variables
	int number, compNumber;
	EditText textField;
	TextView result, gameObjective;
	Button button;
	Random rand = new Random(System.nanoTime());
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		// setting views
		textField = (EditText) findViewById(R.id.textField);
		result = (TextView) findViewById(R.id.resultView);
		gameObjective = (TextView) findViewById(R.id.gameObjective);
		button = (Button) findViewById(R.id.submitButton);
		
		// creating computer number
		compNumber = rand.nextInt(10);
		    
		button.setOnClickListener(new View.OnClickListener() {
				
			@Override
			public void onClick(View v) {
				number = Integer.parseInt(textField.getText().toString());
					
				// checks if correct guess
				if(number == compNumber) {
					result.setText("CORRECT! The nummber was " + compNumber);
				} else {
					result.setText("LOL nope. Guess Again.");
				}
			}
		});
	}
}

 

Splash.java

package com.bwall.thenumbergame;

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

public class Splash extends Activity {
	
	final Context context = this;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		
		Thread timer = new Thread() {
			public void run() {
				
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} finally {
					Intent mainIntent = new Intent(context, MainActivity.class);
					startActivity(mainIntent);
				}
			}
		};
		timer.start();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}
}

 

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splashbackground"
    android:orientation="vertical" >

</LinearLayout>

 

activity_main.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/gameObjective"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="@string/gameObjective"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/textField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/gameObjective"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:inputType="number" />

    <requestFocus />

    <Button
        android:id="@+id/submitButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textField"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="19dp"
        android:text="@string/submitButton" />

    <TextView
        android:id="@+id/resultView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/submitButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="58dp"
        android:textIsSelectable="true" />

</RelativeLayout>

 

TheNumberGame Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bwall.thenumbergame"
    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.bwall.thenumbergame.Splash"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="com.bwall.thenumbergame.SPLASH" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.bwall.thenumbergame.MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 


#1NUCLEAR RABBIT

Posted 07 April 2013 - 01:52 PM

Hello, So I am trying to put an activity that displays a picture in the beginning of my app for 2 seconds and then goes to another activity where the user tries to guess the computers number. Problem is, when I add the new activity (splash) to the manifest file, and change the splash activity as the launcher and the main activity to default it doesnt run anymore! Can someone pleeease help me understand what I am doing wrong...

 

MainActivity.java

package com.bwall.thenumbergame;

import java.util.Random;

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

public class MainActivity extends Activity {
	
	// global variables
	int number, compNumber;
	EditText textField;
	TextView result, gameObjective;
	Button button;
	Random rand = new Random(System.nanoTime());
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		// setting views
		textField = (EditText) findViewById(R.id.textField);
		result = (TextView) findViewById(R.id.resultView);
		gameObjective = (TextView) findViewById(R.id.gameObjective);
		button = (Button) findViewById(R.id.submitButton);
		
		// creating computer number
		compNumber = rand.nextInt(10);
		    
		button.setOnClickListener(new View.OnClickListener() {
				
			@Override
			public void onClick(View v) {
				number = Integer.parseInt(textField.getText().toString());
					
				// checks if correct guess
				if(number == compNumber) {
					result.setText("CORRECT! The nummber was " + compNumber);
				} else {
					result.setText("LOL nope. Guess Again.");
				}
			}
		});
	}
}

 

Splash.java

package com.bwall.thenumbergame;

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

public class Splash extends Activity {
	
	final Context context = this;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		
		Thread timer = new Thread() {
			public void run() {
				
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} finally {
					Intent mainIntent = new Intent("com.bwall.thenumbergame.MAIN");
					startActivity(mainIntent);
				}
			}
		};
		timer.start();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}
}

 

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splashbackground"
    android:orientation="vertical" >

</LinearLayout>

 

activity_main.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/gameObjective"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="@string/gameObjective"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/textField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/gameObjective"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:inputType="number" />

    <requestFocus />

    <Button
        android:id="@+id/submitButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textField"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="19dp"
        android:text="@string/submitButton" />

    <TextView
        android:id="@+id/resultView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/submitButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="58dp"
        android:textIsSelectable="true" />

</RelativeLayout>

 

TheNumberGame Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bwall.thenumbergame"
    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.bwall.thenumbergame.Splash"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="com.bwall.thenumbergame.SPLASH" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.bwall.thenumbergame.MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 


PARTNERS