calling activity from external Activity

*爱你&永不变心* 提交于 2020-01-03 02:05:13

问题


I'd like to start an Activity which is not included in my original .apk. How can I do so? the other Activity is contained in another .apk which is previous version of the current application. Thanks, Eyal.


回答1:


This method is good if you only know the package name:

PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.the.other.app");
startActivity(intent);



回答2:


I'd suggest you read through the Application Fundamentals first - as far as I'm concerned, you will have to use Intents:

As noted earlier, one activity can start another, including one defined in a different application. Suppose, for example, that you'd like to let users display a street map of some location. There's already an activity that can do that, so all your activity needs to do is put together an Intent object with the required information and pass it to startActivity(). The map viewer will display the map. When the user hits the BACK key, your activity will reappear on screen.

So, basically, you define a new intent (you should also take a look at the docs of the Intent class):

Intent myIntent = new Intent();
myIntent.setClassName("com.the.other.app", "com.the.other.app.activityName");
startActivity(myIntent);


来源:https://stackoverflow.com/questions/4842387/calling-activity-from-external-activity

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