Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am new to android and i was following the tutorials of the newboston on youtube. My goal was to set up a new activity and run it while making the original activity a default activity. I followed the tutorial step by step and for some reason even though i do everything correctly, when the program runs,it runs the mainactivity(which i made it default) and doesnt run the activity that i made "main". I dont know what my problem is and i have been stuck for days but cant figure out a solution. Please can anyone help me in solving my problem. Thanks
I am using the Intellij Idea on a windows OS. I am really stuck because without solving this issue i cant move to the next tutorial.

This are the required information-
1. I have two .xml files one is mail.xml and the other is web.xml.
2.I have two java class one is MyActivity.java and the other is Textplay.java
3. Last but not the least the AndroidManifest.xml

Here are the files.

main.xml

XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:paddingLeft="16dp"
                android:paddingRight="16dp" >



</RelativeLayout>



web.xml

XML
<?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" android:background="@drawable/android">

</LinearLayout>


MyActivity.java

Java
package com.example.androidproject;

import android.app.Activity;
import android.os.Bundle;

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


Textplay.java

Java
package com.example.androidproject;

import android.app.Activity;
import android.os.Bundle;

/**
 * Created by user on 05-01-2015.
 */
public class Textplay extends Activity {
    @Override
    protected void onCreate(Bundle flash) {
        super.onCreate(flash);
        setContentView(R.layout.web);
    }
}

AndroidManifest.xml


XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.androidproject"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8"/>
    <application android:label="@string/app_name">

        <activity android:name=".Textplay"
                  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="MyActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="com.example.androidproject.MYACTIVITY"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
    </application>
</manifest> 
Posted
Updated 4-Jan-15 14:39pm
v4

1 solution

You are missing a "." for the android:name attribute:
<activity android:name=".MyActivity"
          android:label="@string/app_name">

You app should launch with the Textplay activity. To start the MyActivity from Textplay,
in the Textplay.java:
Intent intent = new Intent("com.example.androidproject.MYACTIVITY");
startActivity(intent);

+++++++ Round 2 +++++++
Try this, create a new Thread in the onCreate(), let it sleep for 5 seconds, then start the MyActivity:
Thread thread = new Thread(){
  public void run(){
     try {
        sleep(5000); // sleep for 5000 milliseconds
     } catch (InterruptedException e) {
        e.printStackTrace();
     } finally {

        Intent intent = new Intent("com.example.androidproject.MYACTIVITY");
        startActivity(intent);
     }
  }
};
thread.start();
 
Share this answer
 
v4
Comments
Tiffany_Summers 4-Jan-15 21:42pm    
@Peter Leow:- Thank you very much for your help. Do i have to change anything in the androidManifestfile or do i just make the changes you suggested.
Tiffany_Summers 4-Jan-15 22:29pm    
@Peter Leow:- I made a bit of adjustments and made my textplay activity as my launch activity and then it worked fine. After that i placed the intent in the textplay.java and ran the program. What happened is that when i run the program it doesn't show the textplay activity rather it jumps straight to myactivity. I have a feeling that i need to put some sort of sleep function such that it first launches the textplay and then sleeps for couple of seconds and then goes to the myactivity. I tried using the systemclock but it doesnt work. I get same results. This is what i tried-

package com.example.androidproject;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
/**
* Created by user on 05-01-2015.
*/
public class Textplay extends Activity {
@Override
protected void onCreate(Bundle flash) {
super.onCreate(flash);
setContentView(R.layout.web);
Systemclock.sleep(5000);
Intent intent = new Intent("com.example.androidproject.MYACTIVITY");
startActivity(intent);


}
}
Peter Leow 4-Jan-15 23:00pm    
New addition to solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900