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 8530637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:17:39+00:00 2026-06-11T09:17:39+00:00

I checked this question , but it doesn’t appear to answer my problem, which

  • 0

I checked this question, but it doesn’t appear to answer my problem, which is much less involved. I am calling an IntentService from a menu item in my main process. It is currently just a skeleton which puts up a Toast in onHandleIntent() which eventually should appear briefly at the end of the processing to say it’s finished. However it remains on the screen for ever (even when the application is stopped). I tested both with the emulator and my Galaxy S2 with identical results. Can someone point me in the right direction, please?

This is the service code:

 package com.enborne.spine;

 import android.app.IntentService;
 import android.content.Intent;
 import android.util.Log;
 import android.widget.Toast;

 public class SaveFile extends IntentService {
     private final String TAG = "SaveFile";

     public SaveFile() {
         super("SaveFile");
     }

     @Override
     public void onCreate() {
         super.onCreate();
         Log.d(TAG, "Service Started.. ");
     }

     @Override
     public void onDestroy() {
         super.onDestroy();
         Log.d(TAG, "Service Destroyed.. ");
     }

     @Override
     protected void onHandleIntent(Intent intent) {
         // TODO Auto-generated method stub
         Log.d(TAG, "HandleIntent");
         // File saved
         Toast.makeText(this, "File has been saved", Toast.LENGTH_SHORT).show();
     }
 }

(The onCreate and onDestroy overrides are only there temporarily for logging in Eclipse so I can see what’s happening.)

I invoke it from a menu in an activity thus (the messing with context was only because the service didn’t start – some idiot forgot to include it in the manifest!):

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent i;
    switch (item.getItemId()) {
    case R.id.chart:
        i = new Intent(getBaseContext(), Chart.class);
        i.putExtra(KEY_CENTRE_LAT, mCentreLat); // centre coordinate
        i.putExtra(KEY_CENTRE_LONG, mCentreLong); // centre coordinate
        i.putExtra(KEY_RADIUS, mRadius); // effective radius
        startActivity(i);
        break;

    case R.id.save:
        Log.d("SaveFile", "Starting service...");
        //      i = new Intent(getBaseContext(), SaveFile.class);
        i = new Intent(this, SaveFile.class);
        startService(i);
        break;
    }
    return true;
}

EDIT: I found this article, which may explain the problem. To quote one sentence:

However, you can only use Toast in the main GUI thread, or else you run into problems where the Toast message doesn’t disappear after a period (because the main GUI context doesn’t know anything about Toast messages used in a separate thread context).

  • 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-06-11T09:17:41+00:00Added an answer on June 11, 2026 at 9:17 am

    The article linked to in my edit led me to this blog which fixed my problem. I had not seen elsewhere that you cannot issue a toast directly from a service. So my onHandleIntent now looks like this:

    private Handler handler;
    
    @Override
    protected void onHandleIntent(Intent intent)
    {
        Log.d(TAG, "onHandleIntent");
    
        /* Stripped out some code here that I added later to keep it similar to
         * my example above
         */
    
        handler.post(new Runnable()
        {  
    //      @Override
            public void run()
            {
                Toast.makeText(getApplicationContext(), "File has been saved", 
                    Toast.LENGTH_SHORT).show();
            }
        });    // Display toast and exit
    }
    

    (If anyone can explain why I had to comment out the @Override on the run() to avoid an error, I would be grateful. There are several other places in my application that I have had to do that.)

    Edit: I have only just found this post which is virtually the same thing. I don’t know how I missed it before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I checked this post already. But it doesn't answer my question. I want to
I have checked this similar question, but the suggestions did not solve my problem:
I've checked through other questions and surprisingly this question doesn't seem to have been
I've checked for other questions relevant to this, but the only answer is Use
I know that this question is asked a lot, I checked all of the
I am calling a WebMethod from this code: if($(this).attr(checked)) { .. MyWebMethod(variable1, variable2, onSuccessFunction);
I know that this question have been asked several times. But I can't get
Hello i used of answer in this question : Create new class from a
Please see my answer to this question below. It is based upon Kevin's input,
I've seen this question being asked 1000 times, but I'd tried almost all methods

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.