如何在Android Studio中运行特定活动? [英] How to run a certain activity in Android Studio?

查看:175
本文介绍了如何在Android Studio中运行特定活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我在一个应用程序中有一些活动,并且为了查看某个活动的UI或其他内容,我需要运行一个不是该应用程序启动器的活动.

For instance, I have a few activities within one app, and in order to see a certain activity's UI or whatever, I need to run a certain activity that is not the launcher of the app.

一种愚蠢的方法是在启动器中为该活动建立一个门",然后从该门进入该活动.但是,有没有更好的方法可以单独运行某个活动?

One stupid way is to build a "door" for that activity in the launcher and go inside the activity from the door. However, Is there any better way to run a certain activity alone?

推荐答案

非常简单.首先导出您需要运行的活动:

Very easy. Start by exporting the activity you need to run:

在清单的活动声明中添加android:exported="true".这是因为am是外部应用程序,您需要导出活动以允许外部应用程序启动它们.

Add android:exported="true" in the Activity declaration in the Manifest. This is because am is an external application, and you need to export Activities to allow external application to start them.

转到运行"菜单中的编辑配置...".

Go to "Edit Configurations..." in the "Run" menu.

在左窗格中,选择您的应用程序.在右窗格的常规"选项卡的启动选项"部分中,有一个启动:"下拉菜单.

In the left pane, select your application. In the right pane, in the "General" tab, in the "Launch Options" section, there is a "Launch:" dropdown.

选择指定的活动",然后输入清单中显示的活动名称.

Select "Specified Activity", and enter the name of your activity as it appears in your Manifest.

您可以创建任意数量的配置,并根据自己的喜好命名它们,例如指示正在启动的活动.

You can create as many Configurations as you like, and name them according however you like, for example to indicate which activity is being started.

这篇关于如何在Android Studio中运行特定活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆