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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:39:03+00:00 2026-06-05T06:39:03+00:00

I have a strange problem. I have an Activity with a ListView and start

  • 0

I have a strange problem. I have an Activity with a ListView and start a service in the Activity in onCreate.

When I start the App now the Layout of the Activity is not shown until the service has done his work. =( Normaly the service should do his work in the background.

Activity

import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class DealAlertMainActivity extends Activity {

    ListView list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        list = (ListView) findViewById(R.id.list);

        //start service if its not running
        if(isMyServiceRunning() == false)
            startService(new Intent(DealAlertMainActivity.this, DealAlert_Service.class));
    }

    @Override
    public void onStart()
    {
        super.onStart();

        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("keyword", "Test Keyword");
        map.put("title", "Test Title");
        mylist.add(map);
        map = new HashMap<String, String>();
        map.put("keyword", "Test Keyword 2");
        map.put("title", "Test Title 2");
        mylist.add(map);

        SimpleAdapter feeds_list = new SimpleAdapter(this, mylist, R.layout.listview_item,
                    new String[] {"keyword", "title"}, new int[] {R.id.Keyword, R.id.Title});
        list.setAdapter(feeds_list);

    }

...

}

Service

import java.util.ArrayList;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;


public class DealAlert_Service extends Service {

    private NotificationManager mNM;

    public void onCreate()
    {
        super.onCreate();

        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    }





    public int onStartCommand(Intent intent, int flags, int startId) {

        //Do work

        }

    @Override
    public void onDestroy() {
      super.onDestroy();

    }

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

}

Thank you for your help!

  • 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-05T06:39:04+00:00Added an answer on June 5, 2026 at 6:39 am

    Services are automatically in the background from a UI standpoint. They are not automatically in the background from a threading standpoint. onStartCommand() is called on the main application thread, and your UI will be frozen for however long onStartCommand() takes to complete. Hence, any significant work to be done by the service needs to be done in a background thread, whether it is one you create yourself or one you get by switching to IntentService.

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

Sidebar

Related Questions

I have a strange problem in my android app. I have an activity which
I'm having a strange problem with my app - A have a Fragment Activity
I have a strange problem using a MapView in Android. It works fine until
I have a strange problem and really dont know where to start debug. I
I'm having a strange problem with Android 1.6 I have an application that has
I have a strange problem in my android application. I am starting one activity
In my android app i have got an activity that uses a linear layout
i have strange problem doing reporting: i have numerous clients with different issued invoices.
I have strange problem with receiving data from socket. On client im using air
I have a strange problem that I've never encountered before, I have data in

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.