0

我正在尝试创建一个在启动时运行的应用程序。这是一个简单的程序,用于显示我在打开我的 android 设备时想要显示的文本。到目前为止,这就是我所拥有的:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.helloworld"
    android:versionCode="1"
    android:versionName="1.0" > 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 
    <uses-sdk 
        android:minSdkVersion="8" 
        android:targetSdkVersion="11" /> 

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" > 
        <activity
            android:label="@string/app_name"
            android:name=".MainActivity" > 
            <intent-filter > 
                <action android:name="android.intent.action.MAIN" /> 

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

        <receiver android:name="com.mycompany.mybirthday.StartMyActivityAtBootReceiver"> 
            <intent-filter> 
                <action android:name="android.intent.action.BOOT_COMPLETED" /> 
            </intent-filter> 
        </receiver> 
    </application> 
</manifest> 

MainActivity.java

package com.mycompany.mybirthday; 

import android.app.*; 
import android.os.*; 
import android.view.*; 
import android.widget.*; 
import java.util.*; 

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

StartMyActivityAtBootReceiver.java

package com.mycompany.mybirthday; 

import android.app.*; 
import android.os.*; 
import android.view.*; 
import android.widget.*; 
import java.util.*; 
import android.content.*; 

public class StartMyActivityAtBootReceiver extends BroadcastReceiver { 

    @Override
    public void onReceive(Context context, Intent intent) { 
        Intent activityIntent = new Intent(context, MainActivity.class); 
        context.startActivity(activityIntent); 
    } 
}

当我启动我的机器人时,我收到一条消息“不幸的是,我的生日停止了”。我究竟做错了什么?

4

0 回答 0