开发者

Android - Unable to auto start an activity at the time of device bootup?

I am trying to start an activity at devic开发者_运维知识库e bootup.

Stranege thing is that my code is working on emulator but not on an actual device.

I have a file called preferences.xml which has a CheckBoxPreference to set the auto start on and off.

Here is my code :-

public class AutoStartUp extends BroadcastReceiver
{
private static final String TAG = "AutoStartUp";
public void onReceive(Context context, Intent intent)
{
    String action = intent.getAction();
    if(action.equals(Intent.ACTION_BOOT_COMPLETED))
    {
        SharedPreferences sp = context.getSharedPreferences("preferences", 0);
        if(sp.getBoolean("autostartup", false))
        {
            Log.e(TAG, "I AM HERE");
            Intent startupIntent = new Intent(context,  CompleteTaskManager.class);
            context.startActivity(startupIntent);
        }
    }
}
}

Here is my Manifest part for this receiver :-

<receiver android:name=".AutoStartUp" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
     <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    </receiver>

Please Help!!


You can try this FLAG_ACTIVITY_REORDER_TO_FRONT
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜