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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:57:10+00:00 2026-06-14T22:57:10+00:00

I have a weird problem that I can’t solve. I’m trying to open a

  • 0

I have a weird problem that I can’t solve. I’m trying to open a ListActivity from a Service I made of my own. The ListActivity receives foto paths from the service, which has to been show in a list. This is the code of the service:

public void onStart(Intent intent, int startId) {
    // TODO Auto-generated method stub
    super.onStart(intent, startId);
    Toast to=Toast.makeText(this, "entrando en servicio", 1000);
    to.show();
    accederFotosFolder();
    crearArrayFotos();      
    Intent i=new Intent(this.getBaseContext(),Lista.class);
    Bundle b=new Bundle();
    b.putStringArrayList("imagenes",imagenes);
    i.putExtras(b);
    Toast t=Toast.makeText(this, ""+i, 1000);
    t.show();
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setFlags(Intent.FLAG_FROM_BACKGROUND);
    startActivity(i);
}

When I Run this I always have a null pointer Exception.

I checked and nothing is null, not the bundle, not imagenes (which is an ArrayList<String> with 2 elements generated by accederFotosFolder()+crearArrayFotos() ). Neither is the intent. If I comment startActivity(i) everything works, so is that line for sure. First thing I thought was that mi ListActivity had something wrong, but it never goes into it’s code, It just stops at startActivity(i) line.

Any suggestions? It’s driving me mad.

UPDATE

 **That's the logcat output**

11-21 19:02:32.214: E/AndroidRuntime(28980): FATAL EXCEPTION: main
11-21 19:02:32.214: E/AndroidRuntime(28980): java.lang.RuntimeException: Unable to      start service com.example.serviciofotos.Servicio@4166f550 with Intent { cmp=com.example.serviciofotos/.Servicio }: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2518)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.app.ActivityThread.access$1900(ActivityThread.java:134)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.os.Looper.loop(Looper.java:154)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.app.ActivityThread.main(ActivityThread.java:4624)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at java.lang.reflect.Method.invokeNative(Native Method)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at java.lang.reflect.Method.invoke(Method.java:511)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)    
11-21 19:02:32.214: E/AndroidRuntime(28980):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at dalvik.system.NativeStart.main(Native Method)
11-21 19:02:32.214: E/AndroidRuntime(28980): Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.app.ContextImpl.startActivity(ContextImpl.java:871)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at com.example.serviciofotos.Servicio.onStart(Servicio.java:53)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.app.Service.onStartCommand(Service.java:438)
11-21 19:02:32.214: E/AndroidRuntime(28980):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2501)
11-21 19:02:32.214: E/AndroidRuntime(28980):    ... 10 more
  • 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-14T22:57:11+00:00Added an answer on June 14, 2026 at 10:57 pm

    SOLUTION!!!!!

    FINALLY!!! ok, there was 2 mistakes.
    First one is that my line
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); is in the wrong place, It have to be just after the declaration of the intent.

    Second problem is that i was sending an ArrayList to my ListActivity and triying to receive an String (wrong bundle method). So that’s it.

    Thank’s to everyone who wanted help. Here the right code of the service:

      public void onStart(Intent intent, int startId) {
        // TODO Auto-generated method stub
        super.onStart(intent, startId);
        Toast to=Toast.makeText(this, "entrando en servicio", 1000);
        to.show();
        accederFotosFolder();
        crearArrayFotos();
    
        Intent i=new Intent(Servicio.this.getBaseContext(),Lista.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Bundle b=new Bundle();
        b.putStringArrayList("imagenes",imagenes);
        i.putExtras(b);
        getApplication().startActivity(i);
    } 
    

    And the ListActivity

       public class Lista extends ListActivity {
    private Bundle recogerDatos=new Bundle();
    private ArrayList<String> imagenes;
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        recogerDatos=this.getIntent().getExtras();
    
        imagenes=recogerDatos.getStringArrayList("imagenes");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, imagenes);
        setListAdapter(adapter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a weird date rounding problem that hopefully someone can solve. My client
I have a weird problem that i can't figure out a solution for: I've
I have a rather small but weird problem that I can't seem to fix.
I have a very weird problem that I can't understand. This is C code:
I have a weird problem with R that I can't seem to work out.
I've got a weird problem that I can't understand... I have a simple HelloWorld
I have been experiencing a weird problem that I can't find a solution to.
I have a weird problem that I am hoping someone can help me with.
So I have a weird problem. I have an <a/> tag that I am
Hey guys, I have a weird problem. I have an update system that refreshes

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.