Activity does not change

1

I'm a beginner on Android and am creating an app that has two activities ( SplashScreen and ActivityMain ).

I was able to show SplashScreen after a lot of sacrifice, but when I install it on the device, the message appears:

  

****** stopped

Can anyone help me? Below is the code for SplashScreen

package bbacpropaganda.microfapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Handler;
import android.view.WindowManager;

public class SplashScreen extends AppCompatActivity {
    //Set waktu lama splashscreen
    private static int splashInterval = 2000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);


//Após alguns segundos vai para atividade principal
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        new Handler().postDelayed(new Runnable() {


            @Override
            public void run() {
                // TODO Auto-generated method stub
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);
                //jeda selesai Splashscreen
            }

        }, splashInterval);

//Fim de alguns segundos vai para atividade principal



   }




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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
    
asked by anonymous 26.03.2016 / 21:08

1 answer

0

I've been through the same problem before so I decided to help.

First change your AndroidManifest.xml file, as in the example below:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.novoapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:screenOrientation="portrait"
            android:name=".SplashScreen"
            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=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>
    </application>
</manifest>

Note that above, I'm using a Theme of mine, so if you copy the code above change to your theme.

Note also that in the code above I'm using the precedence order, where Activity .SplashScreen comes first and takes about 3 seconds to exit the screen, it starts in Portrait mode and then changes to% with%.

Then change your SplashScreen.java file as done below:

package br.com.novoapp;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;


public class SplashScreen extends Activity{

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;
    private Typeface type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}

Now create a new file called MainActivity or modify it to be able to display this Splash screen, which in the case I used to display a centered image, which is contained in the activity_splash.xml folder, see the following code:

<?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:layout_gravity="center"
    android:background="@color/colorPrimary" >

   <ImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/imgLogo"
        android:src="@drawable/telasplash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"
        tools:ignore="ContentDescription"
        android:layout_gravity="center"
        android:visibility="visible"/>


</RelativeLayout>

Note that in the above code, I put a centered image with a specific background color, which you can modify in the Drawable file, which is in the colors.xml folder.

I hope I have helped.

    
26.03.2016 / 23:11