I use the code below so that my application can automatically start after the download is completed in 10 seconds:
public class BootActivity extends BroadcastReceiver { static final String ACTION = "android.intent.action.BOOT_COMPLETED"; public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(ACTION)) { context.startService(new Intent(context, BootActivity.class)); try { Thread.sleep(10000); Intent newAct = new Intent(); newAct.setClass(BootActivity.this, NewActivity.class); startActivity( newAct ); } catch(Exception e) { e.printStackTrace(); } } } }
But setClass and startActivity cannot be used here.
How can I change it to run it?
source share