I tried using the sample code in this link but it seems outdated and it did not work. So what changes do I have to make and to what files to have my app start automatically
Listen for the ACTION_BOOT_COMPLETE and do what you need to from there. There is a code snippet here.
Update:
Original link on answer is down, so based on the comments, here it is linked code, because no one would ever miss the code when the links are down.
In AndroidManifest.xml (application-part):
...
...
public class BootUpReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MyActivity.class); //MyActivity can be anything which you want to start on bootup...
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Source: https://web.archive.org/web/20150520124552/http://www.androidsnippets.com/autostart-an-application-at-bootup