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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:14:00+00:00 2026-05-27T02:14:00+00:00

Hi i’m facing this problem. I have an application with 2 activities: -Activity A

  • 0

Hi i’m facing this problem. I have an application with 2 activities:
-Activity A (Main activity) showing a list of cars
-If you click on an item list the Activity B is started showing car’s details.

From within activity B you can download info related to that car, a service C in charge of the download is started and a notification is added to the notification bar. If you click the notification you are supposed to see Activity B showing details related to that specific car.

My problem is the following: activity B gets an intent with this extra: carID
So in onCreate it reads this extra and ask the db for that specific car details.
When i call Activity B from activity A everything works fine. But when i call activity B from the notification bar it doesn’t. It always get details about the first car i chose.
So for example, i download Ferrari details, and then Lamborghini details….

In my notification i will see 2 notifications, but both of them open activity B showing Ferrari details.

This is how i create the notifications inside the Service C:

int icon = icona;  
CharSequence tickerText = message;              
long when = System.currentTimeMillis();         
Context context = getApplicationContext();      
CharSequence contentTitle = message;  
CharSequence contentText = appName;      
Intent notificationIntent;
notificationIntent = new Intent(this, ActivityB.class);
notificationIntent.putExtra("carId", carId);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,     PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(NOT_ID, notification);

and this is how i receive the intent in Activity B:

Intent myIntent = getIntent(); 
appId = myIntent.getIntExtra("carId", 0);

At the beginning i didn’t receive any intent at all from the notification…..then i added PendingIntent.FLAG_UPDATE_CURRENT as you can see above and i get it, but it always the first one. I have verified, and i add the correct carId to each intente but i get another one instead……and each time a open the notification this log message appears:

startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { cmp=market.finestraprincipale/.ApplicationActivity bnds=[0,101][320,165] (has extras) }

Can someone help me pls….

  • 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-27T02:14:01+00:00Added an answer on May 27, 2026 at 2:14 am

    (Original answer revised, see edit history for it)

    I’m not actually sure, which part of your system is malfunctioning so I post my test code here, which I tested to work correctly. First there is MyService, then TestActivity which displays the car details in DetailsActivity:

    CarService.java

    public class CarService extends IntentService
    {
        public CarService()
        {
            super("CarService");
        }
    
        protected void onHandleIntent(Intent intent)
        {
            Bundle extras = intent.getExtras();
            if (extras == null)
            {
                Log.e("CarService", "Service onHandleIntent null extras");
                return;
            }
    
            int carId = extras.getInt("carId");
            String carName = extras.getString("name");
            Log.i("CarService", "Service onHandleIntent car = " + carName + " with ID = " + Integer.toString(carId));
    
            Intent notificationIntent;
            notificationIntent = new Intent(this, DetailsActivity.class);
            notificationIntent.putExtra("carId", carId);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
            PendingIntent pending = PendingIntent.getActivity(this, carId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
            Notification notif = new Notification(R.drawable.icon, carName, System.currentTimeMillis());
            notif.flags |= Notification.FLAG_AUTO_CANCEL;
            notif.setLatestEventInfo(getApplicationContext(), carName, "Car Details", pending);
    
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(carId, notif);
        }
    }
    

    TestActivity.java (your main activity)

    public class TestActivity extends Activity implements OnClickListener
    {
        @Override public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.test);
    
            Button btn = (Button) findViewById(R.id.launch);
            btn.setOnClickListener(this);
        }
    
        @Override public void onClick(View v)
        {
            startActivity(new Intent(this, DetailsActivity.class));
        }
    }
    

    test.xml (layout for TestActivity.java)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" a:id="@+id/layout_root" a:orientation="vertical" a:layout_width="fill_parent" a:layout_height="fill_parent">
        <TextView a:id="@+id/test_value"  a:text="Main..." a:layout_width="wrap_content" a:layout_height="wrap_content"/>
        <Button a:id="@+id/launch" a:text="Details" a:layout_width="100dp" a:layout_height="wrap_content"/>
    </LinearLayout>
    

    DetailsActivity.java (car details listed here + launches CarService + notifications lead back to here)

    public class DetailsActivity extends Activity implements OnClickListener
    {
        private String[] cars = new String[]{"Ferrari", "Lamborghini", "Lada", "Nissan", "Opel", "Bugatti"};
        private int id = 0;
    
    
        @Override public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.details);
    
            Button btn = (Button) findViewById(R.id.doit);
            btn.setOnClickListener(this);
    
            Bundle extras = getIntent().getExtras();
            if (extras != null)
            {
                final int id = extras.getInt("carId");
                Log.i("DetailsActivity", "Car ID: " + id);
                TextView tv = (TextView) findViewById(R.id.test_value);
                tv.setText("Car ID = " + Integer.toString(id) + ", which is " + cars[id%6]); // id%6 prevents a crash with the string array when clicking test button over 6 times
            }
        }
    
        @Override public void onClick(View v)
        {
            Intent intent = new Intent(this, CarService.class);
            intent.putExtra("carId", id);
            intent.putExtra("name", cars[id%6]); // id%6 prevents a crash with the string array when clicking test button over 6 times
            startService(intent);
            ++id;
        }
    }
    

    details.xml (layout for TestActivity.java)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" a:orientation="vertical" a:layout_width="fill_parent" a:layout_height="fill_parent">
        <TextView a:id="@+id/test_value" a:text="No details yet: click the button." a:layout_width="wrap_content" a:layout_height="wrap_content"/>
        <Button a:id="@+id/doit" a:text="Test" a:layout_width="100dp" a:layout_height="wrap_content"/>
    </LinearLayout>
    

    I hope all that works correctly as I did make some minor changes on the fly.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into

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.