Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to run javascript in background?
    primarykey
    data
    text
    <p>I have created plugin for background service (to run the application in background) in phonegap .I have created service for run the application in background using android.Then start the service from plugin.In index.html I call that plugin in button click event.When I click the button the service is started. Is it possible using android service run the javascript in background and get alert from background?how to do that? Now I want to run the javascript in background.Is it possible how to get alert in background.also need to call the wcf rest service.</p> <p>please guide me.thanks in advance.</p> <p>My code in Index.html</p> <pre><code>document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { alert("hello"); navigator.notification.alert("hai"); } </code></pre> <p>after starting service My application is run in background.I want this "alert("hello");""navigator.notification.alert("hai");" in background.(ie) alert found in my .html file.But you give code for activity in android.It should run the javascript in background and display alert from that.please guide me.thanks in advance.I have one more doubt this service also run my wcf rest service in background and diaplay alert from that service. please tell me the solution My code for service:</p> <pre><code>public class MyService extends Service { private static final String TAG = "MyService"; MediaPlayer player; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); player = MediaPlayer.create(this, R.raw.braincandy); player.setLooping(false); // Set looping } @Override public void onDestroy() { Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); Log.d(TAG, "onDestroy"); player.stop(); } @Override public void onStart(Intent intent, int startid) { Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); Log.d(TAG, "onStart"); player.start(); Toast.makeText(this, "alert Started", Toast.LENGTH_LONG).show(); } } </code></pre> <p>In this code I have add one player.so after starting service .song is played in foreground,song is played, after pressing home button in emulator(background).I want to show alert like this.how to do that?</p> <p>In my plugin</p> <pre><code>if (CALL_SERVICE_ACTION.equals(action)) { Log.d(TAG, "CALL_SERVICE_ACTION"); ctx.startService(new Intent(ctx, MyService.class)); Intent i = new Intent(ctx, AppNotification.class); ctx.startActivity(i); } </code></pre> <p>I have call your activity after starting service It show alert only in fore ground after pressing home button in emulator.the alert not come( from background)please tell me solution</p> <p>In index.html</p> <pre><code>function callServiceFunction() { window.plugins.BackgroundService.callService('callService', callServiceSuccessCallBack, callServiceFailCallBack); } function callServiceSuccessCallBack(e) { alert("Success"); callNotificationsFunction(); } function callServiceFailCallBack(f) { alert("Failure"); } function callNotificationsFunction() { window.plugins.BackgroundService.callNotifications('callNotifications', callNotificationsSuccessCallBack, callNotificationsFailCallBack); } function callNotificationsSuccessCallBack(e) { alert("Success"); } function callNotificationsFailCallBack(f) { alert("Failure"); } </code></pre> <p></p> <p>while I am clicking background button service created.and It call callNotificationFunction from callservicesuccesscallback.it display alert in foreground.after I am clicking home button in emulator nothing happend, alert not dispalyed from background, please guide me thanks in advance.If I call callNotificationFunction in separate button click nothing happend(alert is not displayed in foreground) and no error in logcat</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload