开发者

Newbie Android Trouble: app opening wrong main.xml?

开发者 https://www.devze.com 2023-04-01 11:25 出处:网络
I am just starting android development so please bear with me. My issue is that when I run my app in the emulator, after my splash screen, the next screen that pops up is from a completely different

I am just starting android development so please bear with me.

My issue is that when I run my app in the emulator, after my splash screen, the next screen that pops up is from a completely different app than the one I am working in. Both screens conflicting are named the same (main.xml) so that may have something to do with it but they are in completely different folders and workspaces. I have been trying to experiment with my code to stop the screen after my splash screen from showing up completely so I could have a better idea of where the problem is occurring but have been unsuccessful.

Does anyone have any idea what might be going wrong or where I should at least 开发者_开发技巧start to look to solve this problem?

files in eclipse: http://imgur.com/kORdH

Main Activity class:

package com.mwmnj.criticmatch;

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

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

main.xml:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:padding="20dp"
    android:weightSum="1">
    <TextView android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/textView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Hello!"
        android:layout_gravity="center" />
    <TextView android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/textView2" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="criticmatch">android:layout_gravity="center"></TextView>
    <Button android:text="Proceed" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/button1"
        android:layout_marginTop="50dp" />
</LinearLayout>

Splash class:

package com.mwmnj.criticmatch;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                } catch (InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent openStartingPoint = new Intent("matt.meyer.criticmatch.MENU");
                    startActivity(openStartingPoint);
                }
            }
        };
        timer.start();
    }
}

splash.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/crbackground"
  >


</LinearLayout>

androidmanifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mwmnj.criticmatch"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <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>

        <activity android:name=".CriticMatchActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="com.mwmnj.criticmatch.CRITICMATCHACTIVITY"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>
</manifest>


Your problem is here:

Intent openStartingPoint = new Intent("matt.meyer.criticmatch.MENU");
startActivity(openStartingPoint);

That's pointing to some other app, as far as I can tell. Try this:

Intent openStartingPoint = new Intent(Splash.this, CriticMatchActivity.class);
startActivity(openStartingPoint);

Using the action name should work, too, as long as it matches the name in the AndroidManifest.xml:

Intent openStartingPoint = new Intent("com.mwmnj.criticmatch.CRITICMATCHACTIVITY");


My guess is that you have the wrong projecte selected in Eclipse, in the package explorer.

Either the project or one if its source files should be selected for the laucher to lauch this app. Even if you are currently editing a source from this project.

0

精彩评论

暂无评论...
验证码 换一张
取 消