How can I run my application or some specific meth

2019-09-02 03:15发布

问题:

I want to run my application in background when i click on windows button. Basically I have some methods of XMPP and when I goes to background it changes its status and presence from online to offline. I want this to be run in background. Just because of the status is offline I am not able to receive any toast notification from XMPP.

If any one has idea about XMPP then please help to resolve this as well.

Any help will be much appreciated.

Thanks, Nishant

回答1:

You cannot make your app run in the background. I think that other IM apps use a push mechanism. So you need a server, when you app is exited, you tell the server to make the user seem still online and when a message arrives for the user, you send a push notification to the device. Whne the user taps the push notifictaion popup, your app will be started.



回答2:

On Windows Phone "normal" apps cannot run continuous in background. XMPP normally requires a persistent long living TCP/IP connection during your complete session.

There are different ways to solve this problem: 1. create a app which can run in background, e.g a location tracking app or voice app

  1. Log off when your app goes in background, you will not receive any message until your login in foreground.

  2. Log off when your app is in background and also use a background service which log on in the interval of eg. 30 minutes and checks for new messages. But that's far away from being realtime and the idea of XMPP ;-)

  3. Use a combination of XMPP and Push messages. XMPP while you are in foreground and Push when you are in background.

  4. create a proxy between your app and the XMPP server and use Push. This means your app does not create the XMPP connection iself. Your app tells only your "proxy server" to login user X now. Your "proxy server" creates the XMPP connection and it can stay there 24/7 connected, doesn't matter whether your app is in background or not. Your app can communicate with your "XMPP proxy" over push or any other protocol choose.

Which solution your choose depends on your unique requirements. For chat apps like WhatsApp a background service is normally not appropriate because your messages are delayed for up to 30 minutes and your are not available while the background service does not run. While for other business apps this may be fine.