Android 2.2: How to make an app to run automaticly on startup & how to make an app start another app

时光毁灭记忆、已成空白 提交于 2020-01-01 11:53:32

问题


The topic pretty much says it all.


回答1:


Use BroadcastReceiver that receives Intent of action BOOT_COMPLETED.

in onReceive() method create an Intent for your activity:

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

 Intent myIntent = new Intent(context, YourActivity.class);
 context.startActivity(myIntent);
}



回答2:


For the application on startup, you need to add the permission

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

to your manifest. Then do as Vladimir wrote.

For starting another app, you need to know the (hopefully official) intent to start it. Otherwise see my reply on question calling an activity that is in another package(android)

For example, starting the LastFM app would be like this:

final Intent i = new Intent("android.intent.action.MAIN");                
i.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(i);


来源:https://stackoverflow.com/questions/4554583/android-2-2-how-to-make-an-app-to-run-automaticly-on-startup-how-to-make-an-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!