I have just gotten into Android app development and have been working on parts of my project in bits and pieces.
I first created my onboarding screens and then made my animated splash screen. However, when I run my application my splash screen does not show and instead loads the onboarding pages first. How can I fix this to make my app first transition through the splash screen before moving on the onboarding screens?
This is my SplashActivity Class code
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_SCREEN = 5000;
// Variables
Animation topAnim;
ImageView image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
// Animations
topAnim = AnimationUtils.loadAnimation(this,R.anim.top_animation);
// Hooks
image = findViewById(R.id.splashScreenLogo);
image.setAnimation(topAnim);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashActivity.this, OnboardingActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_SCREEN);
}
}
This is my OnboardingActivity Class code
public class OnboardingActivity extends AppCompatActivity {
private OnboardingAdapter onboardingAdapter;
private LinearLayout layoutOnboardingIndicators;
private MaterialButton buttonOnboardingAction;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_onboarding);
// Onboarding Screens
layoutOnboardingIndicators = findViewById(R.id.layoutOnboardingIndicators);
buttonOnboardingAction = findViewById(R.id.buttonOnboardingAction);
setupOnboardingItems();
final ViewPager2 onboardingViewPager = findViewById(R.id.onboardingViewPager);
onboardingViewPager.setAdapter(onboardingAdapter);
setupOnboardingIndicators();
setCurrentOnboardingIndicator(0);
onboardingViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
#Override
public void onPageSelected(int position) {
super.onPageSelected(position);
setCurrentOnboardingIndicator(position);
}
});
buttonOnboardingAction.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(onboardingViewPager.getCurrentItem() + 1 < onboardingAdapter.getItemCount()) {
onboardingViewPager.setCurrentItem(onboardingViewPager.getCurrentItem() + 1);
}
else {
startActivity(new Intent(getApplicationContext(), SignUpActivity.class));
finish();
}
}
});
}
}
Edit - My Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mentalhealthapp">
<application
android:allowBackup="true"
android:icon="#drawable/treen_app_logo"
android:label="treen"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashActivity"></activity>
<activity android:name=".HomeActivity" />
<activity android:name=".SignInActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name=".OnboardingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What should I change in my Manifest File?
You need to set the Launch activity as SplashActivity in your AndroidManifest.xml file
<activity
android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I just want to switch activity with a simple button
Button test = findViewById(R.id.please);
test.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("MainActivity","I pass there ");
Intent intent = new Intent(MainActivity.this, TestActivity.class);
startActivity(intent);
Log.d("MainActivity","I pass there too");
}
});
I don't have an error, I just arrive on a white screen and not on my new activity. Logs appear in my console. I also have a log when I create my second activity but this one doesn't appear.
for more code,
This is my manifest :
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomeActivity">
</activity>
<activity android:name=".ScheduleActivity"></activity>
<activity android:name=".MapActivity"></activity>
<activity android:name=".TestActivity"
android:theme="#style/YourTheme">
</activity>
</application>
TestActivity :
public class TestActivity extends AppCompatActivity {
#Override
public void onCreate(#Nullable Bundle savedInstanceState, #Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_test);
Log.d("TestActivity","I arrived in Test Activity !!");
}
}
the button in activity_main :
</android.support.design.widget.AppBarLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="wtf"
android:background="#color/colorAccent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="#+id/please"
/>
Activity_test :
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_map_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello there! :D"/>
You are Overriding wrong onCreate method in TestActivity. You have to override this method:
protected void onCreate(#Nullable Bundle savedInstanceState) {}
it's my first time posting a question and i already tried more than 5 solutions being told in this site, but none of them works for me, the problem is the buttons are clickable, but not going anywhere i wanted them to, but the main page login button that leads to this page works with the same exact code, below is the menu code
public class AdminMenu extends Activity{
Button b1, b2, b3, b4, b5;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.admin_menu);
b1 = (Button)findViewById(R.id.staff);
b2 = (Button)findViewById(R.id.stock);
b3 = (Button)findViewById(R.id.incoming);
b4 = (Button)findViewById(R.id.outgoing);
b5 = (Button)findViewById(R.id.logout1);
b1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, StaffSelection.class);
startActivity(intent);
finish();
}
});
b2.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, StockSelection.class);
startActivity(intent);
finish();
}
});
b3.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, IncomingSelection.class);
startActivity(intent);
finish();
}
});
b4.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, OutgoingSelection.class);
startActivity(intent);
finish();
}
});
b5.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Logging Out...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, Login.class);
startActivity(intent);
finish();
}
});
}
}
then here is the xml for the app interface
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#drawable/background">
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="STAFF"
android:id="#+id/staff"
android:layout_marginTop="23dp"
android:layout_marginLeft="23dp"
android:layout_marginStart="23dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp"
android:background="#52cc85"
android:clickable="true"
android:contextClickable="true" />
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="STOCK"
android:id="#+id/stock"
android:layout_below="#+id/staff"
android:layout_alignLeft="#+id/staff"
android:layout_alignStart="#+id/staff"
android:layout_marginTop="20dp"
android:layout_alignRight="#+id/staff"
android:layout_alignEnd="#+id/staff"
android:textSize="25dp"
android:background="#52cccc"/>
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="INCOMING SHIPMENT"
android:id="#+id/incoming"
android:layout_below="#+id/stock"
android:layout_alignLeft="#+id/stock"
android:layout_alignStart="#+id/stock"
android:layout_marginTop="20dp"
android:layout_alignRight="#+id/stock"
android:layout_alignEnd="#+id/stock"
android:textSize="25dp"
android:background="#52cc85"/>
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="OUTGOING SHIPMENT"
android:id="#+id/outgoing"
android:layout_below="#+id/incoming"
android:layout_alignLeft="#+id/incoming"
android:layout_alignStart="#+id/incoming"
android:layout_marginTop="20dp"
android:layout_alignRight="#+id/incoming"
android:layout_alignEnd="#+id/incoming"
android:textSize="25dp"
android:background="#52cccc"/>
<Button
android:layout_width="150dp"
android:layout_height="70dp"
android:text="LOGOUT"
android:id="#+id/logout1"
android:layout_marginTop="20dp"
android:layout_below="#+id/outgoing"
android:layout_alignRight="#+id/outgoing"
android:layout_alignEnd="#+id/outgoing" />
</RelativeLayout>
and here is the manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.reversesky.mwms">
<application android:allowBackup="true"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".User.Login">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".User.AdminMenu">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".User.StaffMenu">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".User.StaffSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".IS.IncomingSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".OS.OutgoingSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".Stock.StockSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".User.CreateStaff">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".IS.CreateIncoming">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".Stock.CreateStock">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".OS.CreateOutgoing">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
here is the UI1
Here are some Alternative solutions ,
ViewAnimator : This is useful for showing a quick animation, if you want to change the view multiple times in quick succession.
Fragments : Instead of re-drawing the entire view, you can switch out fragments. Each fragment is a kind of mini activity, and overall this will contain the code much better.
Start New Activity : Pass information to an activity to help it set up. The first activity passes information to a common second activity, which knows how to set itself up based off of the information it receives from the first activity.
I tried with your code, it works fine for me
Replace your code like this,
AdminMenu.class
public class AdminMenu extends Activity {
Button b1, b2, b3, b4, b5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admin_menu);
b1 = (Button) findViewById(R.id.staff);
b2 = (Button) findViewById(R.id.stock);
b3 = (Button) findViewById(R.id.incoming);
b4 = (Button) findViewById(R.id.outgoing);
b5 = (Button) findViewById(R.id.logout1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, StaffSelection.class);
startActivity(intent);
}
});
}
}
StaffSelection.class
public class StaffSelection extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".AdminMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StaffSelection"
android:label="#string/app_name"
/>
</application>
According to you add your class and other details.I have done only for Staff button click.
I've cleaned up Your solution a little bit.
Entire AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".AdminMenuActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".CreateIncomingActivity"/>
<activity android:name=".CreateOutgoingActivity"/>
<activity android:name=".CreateStaffActivity"/>
<activity android:name=".CreateStockActivity"/>
<activity android:name=".IncomingSelectionActivity"/>
<activity android:name=".LoginActivity"/>
<activity android:name=".OutgoingSelectionActivity"/>
<activity android:name=".StaffMenuActivity"/>
<activity android:name=".StaffSelectionActivity"/>
<activity android:name=".StockSelectionActivity"/>
</application>
Please keep in mind You should align activities names as you wish.
In my recreation, every single activity (except AdminMenuActivity to demonstrate usage) is as silly as:
package com.stackoverflow.tommus.buttonsnotworking;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class CreateIncomingActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_incoming);
}
}
Please keep in mind you should use proper layout id in all activities.
Again, in my recreation every single layout (except activity_admin_menu to demonstrate usage) is as silly as:
Now is the important part.
My activity_menu_admin is the same as yours:
<Button
android:id="#+id/staff"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginStart="23dp"
android:layout_marginTop="23dp"
android:background="#52cc85"
android:clickable="true"
android:text="STAFF"
android:textSize="25dp"
/>
<Button
android:id="#+id/stock"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/staff"
android:layout_alignLeft="#+id/staff"
android:layout_alignRight="#+id/staff"
android:layout_alignStart="#+id/staff"
android:layout_below="#+id/staff"
android:layout_marginTop="20dp"
android:background="#52cccc"
android:text="STOCK"
android:textSize="25dp"
/>
<Button
android:id="#+id/incoming"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/stock"
android:layout_alignLeft="#+id/stock"
android:layout_alignRight="#+id/stock"
android:layout_alignStart="#+id/stock"
android:layout_below="#+id/stock"
android:layout_marginTop="20dp"
android:background="#52cc85"
android:text="INCOMING SHIPMENT"
android:textSize="25dp"
/>
<Button
android:id="#+id/outgoing"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/incoming"
android:layout_alignLeft="#+id/incoming"
android:layout_alignRight="#+id/incoming"
android:layout_alignStart="#+id/incoming"
android:layout_below="#+id/incoming"
android:layout_marginTop="20dp"
android:background="#52cccc"
android:text="OUTGOING SHIPMENT"
android:textSize="25dp"
/>
<Button
android:id="#+id/logout1"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/outgoing"
android:layout_alignRight="#+id/outgoing"
android:layout_below="#+id/outgoing"
android:layout_marginTop="20dp"
android:text="LOGOUT"
/>
AdminMenuActivity has some changes:
package com.stackoverflow.tommus.buttonsnotworking;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class AdminMenuActivity extends AppCompatActivity {
Button b1, b2, b3, b4, b5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_menu);
b1 = (Button) findViewById(R.id.staff);
b2 = (Button) findViewById(R.id.stock);
b3 = (Button) findViewById(R.id.incoming);
b4 = (Button) findViewById(R.id.outgoing);
b5 = (Button) findViewById(R.id.logout1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateStaffActivity.class);
}
});
b2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateStockActivity.class);
}
});
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateIncomingActivity.class);
}
});
b4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateOutgoingActivity.class);
}
});
b5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Logging Out...", Toast.LENGTH_SHORT).show();
navigateToActivity(LoginActivity.class);
}
});
}
private void navigateToActivity(Class<?> activityClass) {
final Intent intent = new Intent(this, activityClass);
startActivity(intent);
}
}
I am opening new activities with a use of Intents. This way I am sure when creating a new activity I have an activity with proper layout and not messed up ids.
Can you please remove line "android:contextClickable="true" from your b1 button in your xml file and then try again.
In android when you start YouTube you get a view for couple of seconds then start what is after that, like this image attached
Example of Youtube app
another example of reddit app
my approach is create an activity and in onCreate i declare an countdowntimer for seconds just like this code:
new CountDownTimer(2000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
startActivity(new Intent(WelcomingActivity.this, LoginActivity.class));
finish();
}
}.start();
is this a good way to do it ?
Thanks in advance !
Create SplashScreenActivity.java:
public class SplashScreenActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}, 2000); // your screen will disappear after 2 seconds
}
}
Register activity in your AndroidManifest.xml:
<activity android:name="SplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
And create a layout for your splash screen: activity_splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_background" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="your_image" />
</RelativeLayout>
the easiest way to it is
make an activity called splash
then inside the xml for the activity place your logo you want to use in either an ImageView or as a
android:background //in your </LinearLayout>
then in the java class of the activities onCreate simply write
int secondsDelayed = 2;
new Handler().postDelayed(new Runnable() {
public void run() {
startActivity(new Intent(Splash.this, Login.class));
finish();
}
}, secondsDelayed * 1000);
}
I've created 3 buttons. Each should open up different activities. I've tested it on my device and it never opens a new activity. Could it be due to the main.xml file where I've used the onClick feature for the button despite no using it within my main activity.
public class Main extends Activity implements View.OnClickListener{
private Button playButton, rulesButton, aboutButton;
#Override
protected void onCreate(Bundle savedInstanceState) {//when the app starts this method is run
super.onCreate(savedInstanceState);
// Set the layout for fragment_layout.xml
setContentView(R.layout.main_layout);
playButton = (Button) findViewById(R.id.button_play);
playButton.setOnClickListener(this);
rulesButton = (Button) findViewById(R.id.button_rules);
rulesButton.setOnClickListener(this);
aboutButton = (Button) findViewById(R.id.button_about);
aboutButton.setOnClickListener(this);
}
public void buttonPlayClick(){
startActivity(new Intent("com.example.will.sata.openGLActivity"));
}
public void buttonRulesClick(){
startActivity(new Intent("com.example.will.sata.DetailsActivity"));
}
public void buttonAboutClick(){
startActivity(new Intent(""));
}
#Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.button_play:
buttonPlayClick();
break;
case R.id.button_about:
buttonAboutClick();
break;
case R.id.button_rules:
buttonRulesClick();
break;
}
}
}
AndroidManifest.xml
<activity
android:name=".Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.will.sata.DetailsActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.example.will.sata.openGLActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
main.layout.xml
android:id="#+id/button_play"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Play"
android:onClick="PlayGame"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
style="?android:attr/borderlessButtonStyle"
android:focusable="true" />
I have some corrections of your code, I hope it helps:
In main_layout.xml you don't need android:onClick="playGame" because you are using View.OnClickListener in the main class.
You can also use the android:onClick="playGame", but your code in the Main.class would be like this:
public class Main extends Activity {
private Button playButton, rulesButton, aboutButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
playButton = (Button) findViewById(R.id.button_play);
rulesButton = (Button) findViewById(R.id.button_rules);
aboutButton = (Button) findViewById(R.id.button_about);
}
public void playGame(View v) {
switch (v.getId())
{
case R.id.button_play:
Intent intent = new Intent(Main.this, OpenGLActivity.class);
startActivity(intent);
break;
case R.id.button_rules:
Intent intent = new Intent(Main.this, DetailsActivity.class);
startActivity(intent);
break;
}
}
To register a new activity in AndroidManifest.xml you just need to do this
<activity android:name="com.example.will.sata.OpenGLActivity"/>
<activity android:name="com.example.will.sata.DetailsActivity"/>`
To start a new activity from Main.class you have to do this (It is really important to register the Activity first in the AndroidManifest.xml):
Intent intent = new Intent(Main.this, OpenGLActivity.class);
startActivity(intent);
Intent intent = new Intent(Main.this, DetailsActivity.class);
startActivity(intent);
Tip: be careful with the naming conventions