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

  • Home
  • SEARCH
  • 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 3797084
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:20:48+00:00 2026-05-19T13:20:48+00:00

I’m making an app that sends a notification to the status bar, it sends

  • 0

I’m making an app that sends a notification to the status bar, it sends the notification when stepping through the code in the debugger, however it never sends the notification when run in realtime.

Here is my runnable that generates the notification, again when stepping through this code in the debugger the notification runs however in realtime nothing happens.

public class NewsEvents_Service extends Service {
    private static final String NEWSEVENTS = "newsevents";
    private static final String KEYWORDS = "keywords";
    private NotificationManager mNM;
    private ArrayList<NewsEvent> neList;
    private int count;

    @Override
    public void onCreate() {
        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        neList = new ArrayList<NewsEvent>();
        getKeywords();
        //getNewsEvents();

        Thread thr = new Thread(null, mTask, "NewsEvents_Service");
        thr.start();
        Log.d("Thread", "IT STARTED!!!!!!????!!!!!!!!!!!!!!!?!!?");
    }

    @Override
    public void onDestroy() {
        // Cancel the notification -- we use the same ID that we had used to start it
    mNM.cancel(R.string.ECS);
        // Tell the user we stopped.
        Toast.makeText(this, "Service Done", Toast.LENGTH_SHORT).show();
    }

    /**
     * The function that runs in our worker thread
     */
    Runnable mTask = new Runnable() {
        public void run() {
        getNewsEventsFromWeb();
    for(NewsEvent ne : neList){
            Log.d("Thread Running", "Service Code running!!!!!!!!!!!!!!!");

            String body = ne.getBody().replaceAll("\\<.*?>", "");
            String title = ne.getTitle();
            for(String s : keyWordList){
                if(body.contains(s) || body.contains(s.toLowerCase()) ||
                    title.contains(s) || title.contains(s.toLowerCase())){
                ne.setInterested(true);
                }
            }

            if(ne.isInterested() == true ){
                    Notification note = new Notification(R.drawable.icon,
                        "New ECS News Event", System.currentTimeMillis());
                    Intent i = new Intent(NewsEvents_Service.this, FullNewsEvent.class);
                    i.putExtra("ne", ne);
                    PendingIntent pi = PendingIntent.getActivity(NewsEvents_Service.this, 0,
                        i, 0);


                    note.setLatestEventInfo(NewsEvents_Service.this, "New Event", ne.getTitle(), pi);
                    note.flags = Notification.FLAG_AUTO_CANCEL;
                    mNM.notify(R.string.ECS, note);
            }

        }
        }
    };

    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }
    /**
     * Show a notification while this service is running.
     */
    private void getNewsEventsFromWeb() {

    HttpClient client = new DefaultHttpClient();
    HttpGet get;

        try {
                get = new HttpGet(getString(R.string.jsonnewsevents));
            ResponseHandler<String> response = new BasicResponseHandler();
            String responseBody = client.execute(get, response);

            String page = responseBody;
            Bundle data = new Bundle();         
            data.putString("page",page);
            Message msg = new Message();
            msg.setData(data);

            handler.sendMessage(msg);

        }
        catch (Throwable t) {
            Log.d("UpdateNews", "PROBLEMS");
        }
    }

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            String page = msg.getData().getString("page");



            try {  
               JSONArray parseArray = new JSONArray(page);  

               for (int i = 0; i < parseArray.length(); i++) {  
                   JSONObject jo = parseArray.getJSONObject(i);  

                   String title = jo.getString("title");  

                   String body =jo.getString("body");

                   String pd = jo.getString("postDate");  

                   String id = jo.getString("id");


                   NewsEvent ne = new NewsEvent(title, pd , body, id);

                   boolean unique = true;
                   for(NewsEvent ne0 : neList){
                   if(ne.getId().equals(ne0.getId())){
                      unique = false;
                   }else{
                       unique = true;
                   }
                   }

                   if(unique == true){
                   neList.add(ne);
                   }
               }  
              } catch (JSONException e) {  
               // TODO Auto-generated catch block  
               e.printStackTrace();  
              }
        }
    };
    private ArrayList<String> keyWordList;

    public void getNewsEvents(){
    try {
        InputStream fi = openFileInput(NEWSEVENTS);

        if (fi!=null) {
            ObjectInputStream in = new ObjectInputStream(fi);
                    neList = (ArrayList<NewsEvent>) in.readObject();
                    in.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }
    if(neList == null){
        neList = new ArrayList<NewsEvent>();
    }
    }


    public ArrayList<String> getKeywords(){
    try {
        InputStream fi = openFileInput(KEYWORDS);

        if (fi!=null) {
            ObjectInputStream in = new ObjectInputStream(fi);
                    keyWordList = (ArrayList<String>) in.readObject();
                    in.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }
    if(keyWordList == null){
        keyWordList = new ArrayList<String>();
        return keyWordList;
    }

    return keyWordList;
    }

    /**
     * This is the object that receives interactions from clients.  See RemoteService
     * for a more complete example.
     */
    private final IBinder mBinder = new Binder() {
        @Override
        protected boolean onTransact(int code, Parcel data, Parcel reply,
                        int flags) throws RemoteException {
            return super.onTransact(code, data, reply, flags);
        }
    };
}

Here is my activity that schedules the service to run

public class NewsEvents extends ListActivity{
    private URL JSONNewsEvents;
    private ArrayList<NewsEvent> neList;
    private ArrayList<String> keyWordList;
    private Worker worker;
    private NewsEvents ne;
    public static final String KEYWORDS = "keywords";
    private static final String NEWSEVENTS = "newsevents";
    public static final int ONE_ID = Menu.FIRST+1;


    private PendingIntent newsAlarm;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newsevents);
        ne = this;
        neList = new ArrayList<NewsEvent>();

        try {
        JSONNewsEvents = new URL(getString(R.string.jsonnewsevents));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
        worker = new Worker(handler, this);

        setListAdapter(new IconicAdapter());
        getKeywords(); 
        worker.execute(JSONNewsEvents);
    }

        @Override
    protected void onStop() {
        super.onStop();
        writeNewsEvents() ;
    }

        @Override
    protected void onPause(){
        super.onPause();
        writeNewsEvents();  
    }


    private void writeNewsEvents() {
    try {
        OutputStream fi = openFileOutput(NEWSEVENTS, 0);

        if (fi!=null) {
            ObjectOutputStream out = new ObjectOutputStream(fi);
            out.writeObject(neList);
            out.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }

    }
    /**
     * @return
     */

    public ArrayList<String> getKeywords(){
    try {
        InputStream fi = openFileInput(KEYWORDS);

        if (fi!=null) {
            ObjectInputStream in = new ObjectInputStream(fi);
                    keyWordList = (ArrayList<String>) in.readObject();
                    in.close();
        }
    }
    catch (java.io.FileNotFoundException e) {
        // that's OK, we probably haven't created it yet
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG)
            .show();
    }
    if(keyWordList == null){
        keyWordList = new ArrayList<String>();
        return keyWordList;
    }

    return keyWordList;
    }

    public void onListItemClick(ListView parent, View v,
        int position, long id) {
    startFullNewsEvent(neList.get(position));
    }

    /**
     * @param newsEvent
     */
    public void startFullNewsEvent(NewsEvent ne) {
    Intent intent = new Intent(this, FullNewsEvent.class);
    intent.putExtra("ne", ne);
    this.startActivity(intent);
    finish();
    }



    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            String page = msg.getData().getString("page");



            try {  
               JSONArray parseArray = new JSONArray(page);  

               for (int i = 0; i < parseArray.length(); i++) {  
                   JSONObject jo = parseArray.getJSONObject(i);  

                   String title = jo.getString("title");  

                   String body =jo.getString("body");

                   String pd = jo.getString("postDate");  

                   String id = jo.getString("id");


                   NewsEvent ne = new NewsEvent(title, pd , body, id);

                   boolean unique = true;
                   for(NewsEvent ne0 : neList){
                   if(ne.getId().equals(ne0.getId())){
                      unique = false;
                   }else{
                       unique = true;
                   }
                   }

                   if(unique == true){
                   neList.add(ne);
                   }
               }  
              } catch (JSONException e) {  
               // TODO Auto-generated catch block  
               e.printStackTrace();  
              }
              ne.setListAdapter(new IconicAdapter());

        }
    };

    public class IconicAdapter extends ArrayAdapter<NewsEvent> {
    IconicAdapter() {
        super(NewsEvents.this, R.layout.rownews, neList);
    }

    public View getView(int position, View convertView,ViewGroup parent) {
        LayoutInflater inflater=getLayoutInflater();

        View row=inflater.inflate(R.layout.rownews, parent, false);
        TextView label=(TextView)row.findViewById(R.id.label);
        ImageView image= (ImageView)row.findViewById(R.id.icon);

        String body = neList.get(position).getBody();
        body.replaceAll("\\<.*?>", "");
        String title = neList.get(position).getTitle();
        for(String s : keyWordList){
            if(body.contains(s) || body.contains(s.toLowerCase()) ||
                title.contains(s) || title.contains(s.toLowerCase())){
            neList.get(position).setInterested(true);
            }
        }

        if(neList.get(position).isInterested() == true){
            image.setImageResource(R.drawable.star);
        }


        label.setText(neList.get(position).getTitle());

        return(row);
    }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        populateMenu(menu); 
        return(super.onCreateOptionsMenu(menu));
    }

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return(applyMenuChoice(item) || super.onOptionsItemSelected(item));
    }

    //Creates our activity to menus
    private void populateMenu(Menu menu) { 
        menu.add(Menu.NONE, ONE_ID, Menu.NONE, "Home");

    }

    private boolean applyMenuChoice(MenuItem item) { 
        switch (item.getItemId()) {

        case ONE_ID: startHome(); return(true);

        }
    return(false);
    }
    public void startHome() {
        Intent intent = new Intent(this, ECS.class);
        this.startActivity(intent);
        finish();
    }

}
  • 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-19T13:20:49+00:00Added an answer on May 19, 2026 at 1:20 pm

    Race conditions, I’m making an HTTP Request and then handing it off to a handler, immediately following that I iterator through the array list, which at full speed is empty because the HTTP hasn’t completed. In debugging it all slows down so the HTTP is complete and all works well.
    Threads and Network Connections, a deadly combination.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.