Hello. I am new to Android Programming, and am using Android Studio to practice with. Right now, I am trying to learn how to create a new Activity and transition from it to my main Activity. So far, I have my MainActivity up and running. The code is:

package com.example.cory2.thezoo3;

import android.media.MediaPlayer;
import android.os.TransactionTooLargeException;
import android.provider.MediaStore;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.transition.Fade;
import android.transition.TransitionInflater;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    int images[] = {R.drawable.elephant, R.drawable.crocodile, R.drawable.moose, R.drawable.bison, R.drawable.lion};
    int current = 0;
    private ImageView imageView;
    private Button previousButton, nextButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.imageView);
        previousButton = (Button) findViewById(R.id.previous);
        nextButton = (Button) findViewById(R.id.next);
        final MediaPlayer clk = MediaPlayer.create(this, R.raw.click);
        final MediaPlayer sound1 = MediaPlayer.create(this, R.raw.bis);
        final MediaPlayer sound2 = MediaPlayer.create(this, R.raw.croc);
        final MediaPlayer sound3 = MediaPlayer.create(this, R.raw.ele);
        final MediaPlayer sound4 = MediaPlayer.create(this, R.raw.lion);
        final MediaPlayer sound5 = MediaPlayer.create(this, R.raw.moose);
        final MediaPlayer music = MediaPlayer.create(this, R.raw.jungle);
        imageView.setImageResource(R.drawable.zoo);
        Log.i("ProjectLogging", "The Zoo");
        music.start();
        music.setLooping(true);
        previousButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                music.start();
                music.setLooping(true);
                clk.start();
                if(current !=0) {
                    current--;
                    imageView.setImageResource(images[current]);
                    if (current==0)
                        sound3.start();
                    else if (current ==1)
                        sound2.start();
                    else if (current==2)
                        sound5.start();
                    else if (current ==4)
                        sound1.start();
                    else if (current==5)
                        sound4.start();
                }
                else if (current == 0) {
                    current=(images.length-1);
                    imageView.setImageResource(images[current]);
                    if (current==0)
                        sound3.start();
                    else if (current ==1)
                        sound2.start();
                    else if (current==2)
                        sound5.start();
                    else if (current ==4)
                        sound1.start();
                    else if (current==5)
                        sound4.start();
                }

            }
        });
        nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                music.start();
                music.setLooping(true);
                clk.start();
                if(!(current > (images.length-1))) {
                    imageView.setImageResource(images[current]);
                    current++;
                    if (current==0)
                        sound3.start();
                    else if (current ==1)
                        sound2.start();
                    else if (current==2)
                        sound5.start();
                    else if (current ==4)
                        sound1.start();
                    else if (current==5)
                        sound4.start();
                }
                else if (current > (images.length-1)) {
                    current=0;
                    imageView.setImageResource(images[0]);
                    if (current==0)
                        sound3.start();
                    else if (current ==1)
                        sound2.start();
                    else if (current==2)
                        sound5.start();
                    else if (current ==4)
                        sound1.start();
                    else if (current==5)
                        sound4.start();
                }
            }
        });
    }

    @Override
    public void onClick(View view) {
    }

    @Override
    public void onResume() {
        final MediaPlayer music = MediaPlayer.create(this, R.raw.jungle);
        super.onResume();
        music.start();
        music.setLooping(true);
        Log.i("ProjectLogging", "Continuing the Zoo");
    }

    @Override
    public void onPause() {
        final MediaPlayer music = MediaPlayer.create(this, R.raw.jungle);
        super.onPause();
        music.stop();
        Log.i("ProjectLogging", "Pausing the Zoo");
        Log.d("PRojectLogging", "Paused on " + current);
    }

}

And my activity xml is:

<?xml version="1.0" encoding="utf-8"?> <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="16dp"
    android:paddingLeft="16dp"
    android:paddingTop="16dp"
    android:paddingRight="16dp"
    android:orientation="horizontal"
    tools:context="com.example.cory2.thezoo3.MainActivity"> <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"> <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/zoo" /> </LinearLayout> <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center|bottom"
        android:layout_centerHorizontal="true"
        android:weightSum="1"> <Button
            android:id="@+id/previous"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignBottom="@+id/next"
            android:background="@drawable/left" /> <Button
            android:id="@+id/next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/right" /> </LinearLayout> </RelativeLayout>

What I want to do is is create a new activity that has a starting screen, and after two seconds, transitions to the app I have provided. That is what I am having trouble with. Thank you for assistance.

What I want to do is is create a new activity that has a starting screen, and after two seconds, transitions to the app I have provided.

Sounds like you need something call "splash screen"

You can use TIME_OUT = 2000; under the MainActivity to start new activity after a specific time period. For creating new activity, follow the procedure as mentioned by @rproffitt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.