Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:35:56+00:00 2026-05-30T13:35:56+00:00

I have created plugin for background service (to run the application in background) in

  • 0

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.

please guide me.thanks in advance.

My code in Index.html

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
alert("hello");
navigator.notification.alert("hai");
}

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:

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();
    }
}

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?

In my plugin

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);

}

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

In index.html

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");
}

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:35:57+00:00Added an answer on May 30, 2026 at 1:35 pm

    In order to show alert in your background. Create an Activity which runs as a dialog.
    For example create an activity like this

    public class AppNotification extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AlertDialog alertDialog = new AlertDialog.Builder(AppNotification.this)
                .create();
        alertDialog.setTitle("Alert");
        alertDialog.setMessage("Something");
    
        alertDialog.setButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        finish();                       
                    }
                }); 
        alertDialog.show();
    }
    
    }
    

    Also In manifest file use this

     <activity
            android:name=".AppNotification"
            android:theme="@android:style/Theme.Dialog" >
     </activity>
    

    And Call this activity when ever you want to show some notifications like this

    Intent i = new Intent(context, AppNotification.class);
    context.startActivity(i);
    

    In Order to Give Notifications use

    navigator.notification.alert("hai"); // For foreground
    window.plugins.BackgroundService.callNotifications('callNotifications',
    callNotificationsSuccessCallBack, callNotificationsFailCallBack); // For Background
    

    Just as you used service plugin to call the service you use the call notifications.And then perform the actions like this

    else if (CALL_NOTIFICATION_ACTION.equals(action)) {
    Log.d(TAG, "CALL_NOTIFICATION_ACTION");
    
    Intent i = new Intent(ctx, AppNotification.class);
    context.startActivity(i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the jQuery Tools Scrollable plugin - http://flowplayer.org/tools/scrollable.html#navigator I have created a
Using VB6, I have created an Outlook plugin, that has a property page. The
I develop an app using PhoneGap. I got a service which is in background
I have created a slider using jquery and the slides plugin . I wanted
I have created a plugin, that ckecks authorization status and gives access for using
I am using wordpress 3.3.1 with twentyten theme, i have created a plugin to
I have created an Eclipse plugin which creates a view in Eclipse. Currently it
I have created a simple WordPress plugin that automatically sets my new sites up
I have a engine style Rails plugin from which I can create a gem
Background: We have a project with many modules. We're using EntityFramework 4.2 with FluentAPI

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.