1

I have an android program with 2 layouts. The first layout is Login. When the login is started first, I have no problem. When I try to change in AndroidManifest from login to splash layout, I got an error. The error is like the title of this posts.

In this android manifest, I change my code from :

<?xml version="1.0" encoding="utf-8"?>

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

    <activity
        android:name=".Login"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</application>

to :

<?xml version="1.0" encoding="utf-8"?>

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

    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Here is the layout for login:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Login">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Your total is 0"
    android:textSize="45dp"
    android:gravity="center"
    android:id="@+id/tvDisplay"
    />

<Button
    android:layout_width="250dp"
    android:layout_height="100dp"
    android:text="Add One"
    android:gravity="center"
    android:layout_gravity="center"
    android:id="@+id/bAdd"
    android:textSize="20dp"/>
<Button
    android:layout_width="250dp"
    android:layout_height="100dp"
    android:text="Substract One"
    android:gravity="center"
    android:layout_gravity="center"
    android:id="@+id/bSub"
    android:textSize="20dp"/>

And here the layout of splash:

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

And structure of my code :

enter image description here

Log in logcat:

enter image description here

Here splash.java enter image description here

How can I fix my code?

11
  • remove the <intent-filter> from the activity you dont want to start first. you gave your app 2 activities that it tries to launch at the same time. might not be the problem the error says, BUT is a problem Commented Sep 10, 2015 at 11:10
  • What is error message you got in logcat? Commented Sep 10, 2015 at 11:17
  • Please post the code of the login and Splash and also the xml files of the layout if possible Commented Sep 10, 2015 at 11:35
  • @JacobusConradi i have updated my post, please checked Commented Sep 10, 2015 at 14:11
  • 1
    try removing the android:background="@drawable/sertifikat" from splash.xml Commented Sep 10, 2015 at 15:33

4 Answers 4

1

Hey You missed some small things

Here is a small example from your code on Github that i wrote

This is running example of your code

Other than the ending tags The <intent-filter> should only be one

most probably the problem lies in your @drawable

as well as look at these tutorials they are great

http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/

Sign up to request clarification or add additional context in comments.

Comments

0

Obviously,you have lost a character '/' in the splash layout at the end.

1 Comment

no, i just forget to add more line to end tag of the end of splash layout
0

You are missing the closing tag of your LinearLayout in splash.xml. Add </LinearLayout> to the end of the file. You also might want to consider using an ImageView with android:scaleType="centerCrop" instead of using a LinearLayout with a background. Using android:background will stretch to fit the size of the screen, which can give a different aspect ratio on different devices, whereas an ImageView will scale it to maintain the aspect ratio (depending on the scaleType).

Also, a LinearLayout is not appropriate for a single image, since it is meant to be a container for other views.

1 Comment

No, i don't miss it. I just forget to add the end of tag of linearlayout of the end of the code
0

For better performance I recommend you to follow this : http://www.cutehacks.com/blog/2014/01/13/splash-screens

If you use an high end device you won't see a big difference, but for common devices you will see an huge improvement

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.