How can I programmatically close an application?

后端 未结 5 1186
抹茶落季
抹茶落季 2021-01-14 02:08

I am looking for code for a button that completely closes my app.

I tried with some stuff from Google, but my app is still running in the background. I need to close

5条回答
  •  -上瘾入骨i
    2021-01-14 02:55

    Maybe this link will help developer page

    I quoted the part below that i think might help you.

    Shutting down components

    A content provider is active only while it's responding to a request from a ContentResolver. And a broadcast receiver is active only while it's responding to a broadcast message. So there's no need to explicitly shut down these components.

    Activities, on the other hand, provide the user interface. They're in a long-running conversation with the user and may remain active, even when idle, as long as the conversation continues. Similarly, services may also remain running for a long time. So Android has methods to shut down activities and services in an orderly way:

    An activity can be shut down by calling its finish() method. One activity can shut down another activity (one it started with startActivityForResult()) by calling finishActivity().

    A service can be stopped by calling its stopSelf() method, or by calling Context.stopService().

    Components might also be shut down by the system when they are no longer being used or when Android must reclaim memory for more active components. A later section, Component Lifecycles, discusses this possibility and its ramifications in more detail.

提交回复
热议问题