user1155857
user1155857

Reputation:

starting the android app at start of phone

I want my android activity to be displayed on start of the phone but the app is crashing, and I m unable to take the log as well. Here is the code Manifest

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

    <uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
         <receiver android:enabled="true" android:name=".BootUpReceiver"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

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

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

</manifest>

BOOTUPRECEIVER.JAVA

package com.example.sample;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootUpReceiver extends BroadcastReceiver{


     @Override
     public void onReceive(Context context, Intent intent) {

         Intent i = new Intent(context, StartupActivity.class); 
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i); 

     }
    }

STARTUPACTIVITY.JAVA

package com.example.sample;

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

import com.android.R;

public class StartupActivity extends Activity {



     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);


     }
    }

Could some one help me with the issue

EDIT: 03-20 16:05:24.519: E/AndroidRuntime(2709): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android/com.android.StartupActivity}: java.lang.ClassNotFoundException: com.android.StartupActivity in loader dalvik.system.PathClassLoader[/data/app/com.android-1.apk] 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.os.Handler.dispatchMessage(Handler.java:99) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.os.Looper.loop(Looper.java:130) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.app.ActivityThread.main(ActivityThread.java:3687) 03-20 16:05:24.519: E/AndroidRuntime(2709): at java.lang.reflect.Method.invokeNative(Native Method) 03-20 16:05:24.519: E/AndroidRuntime(2709): at java.lang.reflect.Method.invoke(Method.java:507) 03-20 16:05:24.519: E/AndroidRuntime(2709): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 03-20 16:05:24.519: E/AndroidRuntime(2709): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 03-20 16:05:24.519: E/AndroidRuntime(2709): at dalvik.system.NativeStart.main(Native Method) 03-20 16:05:24.519: E/AndroidRuntime(2709): Caused by: java.lang.ClassNotFoundException: com.android.StartupActivity in loader dalvik.system.PathClassLoader[/data/app/com.android-1.apk] 03-20 16:05:24.519: E/AndroidRuntime(2709): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 03-20 16:05:24.519: E/AndroidRuntime(2709): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 03-20 16:05:24.519: E/AndroidRuntime(2709): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 03-20 16:05:24.519: E/AndroidRuntime(2709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565) 03-20 16:05:24.519: E/AndroidRuntime(2709): ... 11 more

Upvotes: 0

Views: 173

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93728

In Android 3.0 and higher, an bootup reciever will not run until the activity has been launched at least once by hand. So most likely you aren't ever running.

You aren't appearing in the grid because you have no launcher activity. Add this to the activity tag in your manifest

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Then run the app once. After that it ought to work.

Upvotes: 1

Related Questions