开发者

I don't want to close my app in Android?

When I run my application, it is running as it is, but i don't want to close main screen. When any person want to close that activity than no one can c开发者_高级运维lose that application Means in short, Once my app start, no one can interact other application It is possible in android?

Please give me ans.

Thanks,

Pintu


Short of rooting the device and drastically re-writing the operating system, no, you cannot make it impossible for someone to switch tasks. The hardware task-switcher is built into most Android devices.

More importantly, you should not. Android users rely on their devices remaining functional. While it's tempting to imagine using Android as a simple basis for integrated device development, it has always been intended as a multi-application platform.


You can acheive this to some extent by considering how an application actually is closed. It is either when the user presses the back key or the home key. You can, in your main activity, override these event listeners and act upon them accordingly. This code show how to catch the back key press:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

   if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        // Your code here
   }

}

There are of course way to exit your application anyway. But there also methods to bring it to front again (for example running a background service and firing intents from there when you app is no longer in front).

Just remember this is far from common practise and should absolutely not be used in an app you plan on placing on the Android Market.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜