Android - 如何仅通过单击应用程序图标来执行项目的主要功能?

发布于 2024-10-30 13:05:08 字数 171 浏览 2 评论 0原文

我正在制作一个应用程序,并且需要仅通过单击其图标来执行其主要功能。

换句话说,没有布局,没有小部件,只是它的工作。

一旦用户单击该图标,它就应该执行其主要功能。我想到的一种方法是将所有代码放在 onCreate 函数中。

或者如果还有其他方法请分享给我。

I am making an app and required to execute its main functionality only by clicking on its icon.

In other words no layout no widget just its working.

As soon as user click on the icon it should execute its main functionality. One way I think of is to put all the code in onCreate function.

Or if there is any other way please share with me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

策马西风 2024-11-06 13:05:08

您必须有一个用户启动的活动。该活动只需在从 onResume() 返回时调用 finish() 即可不显示(您还需要设置 android:theme="@android:style/Theme.NoDisplay")。如果活动非常简短,则实际工作可能发生在 onCreate() 或此类活动中,否则您需要启动一个服务来负责在其线程中完成工作。

然而。

当用户触摸应用程序图标时,它不执行任何操作,这是一种非常糟糕的体验。我强烈建议不要这样做。您的应用程序中不应该有一个不会实际启动该应用程序的主入口。我可以向您保证,这样做导致您的应用评级因人们不理解您的应用而降低。 (特别是如果这实际上是您的应用程序的主要活动,因为它们会点击市场中的“打开”按钮,但它不会执行任何操作。太棒了。)

我不知道您在做什么,但用户可以按按钮从他们的主屏幕通常应该使用小部件来实现,例如电源小部件。这使得用户更清楚正在发生的事情,特别是因为在视觉上你可以让它看起来像他们按下的按钮而不是他们正在启动的应用程序。

You must have an Activity that the user launches. That activity can just call finish() by the time it returns from onResume() to not be shown (you'll also need to set android:theme="@android:style/Theme.NoDisplay"). The actual work can happen in onCreate() or such of the activity if it is very brief, otherwise you'll need to start a service which takes care of doing the work in its thread.

HOWEVER.

Having an app icon that does nothing when the user touches it is a pretty poor experience. I strongly recommend against that. You shouldn't have a main entry into your app that doesn't actually launch the app. I can assure you, doing so will result in your app rating getting lowered due to people not understanding your app. (Especially if this is actually the main activity if your app, because they will hit the "open" button in market and it will do nothing. Sucktastic.)

I don't know what you are doing, but buttons for the user to press from their home screen should generally be implemented with a widget, like the power widget. This makes it much more clear to the user what is going on, especially since visually you can make this look like a button they are pressing rather than an app they are launching.

分开我的手 2024-11-06 13:05:08

如果您只想在后台做一些工作,您可以使用服务,这可以在活动的 onCreate 方法上调用。否则,您可以使用线程来执行所需的任务,并在活动的 onCreate 上再次执行该线程。这就是你的意思吗?

If you just want to do some job on the background you could use a Service, this could be invoked on the onCreate method of the activity. Otherwise you could use a thread to perform your required task, and execute this thread again on the onCreate of the activity. Is that what you meant?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文