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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:08:40+00:00 2026-06-13T10:08:40+00:00

I have a fairly simple app that takes the input from a user and

  • 0

I have a fairly simple app that takes the input from a user and then sets it as a notification. The user can create as many notifications as he/she likes. I want the user to click the notification and get taken to a new activity called ResultActivity. ResultActivity in turn reads in the putExtras from the notifications intent and shows it to the user. The code below allows me to do almost everything I wanted, except anytime a notification is pressed, I receive the putExtra of the last created notification.

Intent notificationIntent = new Intent(ctx, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, i,notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);

NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

Resources res = ctx.getResources();
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
builder.setContentIntent(contentIntent)
    .setSmallIcon(R.drawable.ic_launcher)
    .setLargeIcon(BitmapFactory.decodeResource(res,R.drawable.ic_launcher))
    .setTicker("Remember to " + text.getText())
    .setWhen(System.currentTimeMillis()).setAutoCancel(true)
    .setContentTitle(text.getText());

// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);
String pass = text.getText().toString();

resultIntent.putExtra("title", pass);
resultIntent.putExtra("uid", i);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);

new Uri.Builder().scheme("data").appendQueryParameter("text", "my text").build();
builder.setContentIntent(resultPendingIntent);

Notification n = builder.build();
n.flags = Notification.FLAG_NO_CLEAR;
nm.notify(i++, n);
text.setText(null);
  1. Open the application

  2. Type in “One”

  3. Hit ok

  4. Notification is sent

  5. Open the application

  6. Type in “Two”

  7. Hit ok

  8. Notification is sent

Now you have two notifications. One that says “One” and one that says “Two”. If you click on the notification “Two” it takes you to a screen that says “Two”. Perfect!

If you click on the notification “One” it takes you to a screen that says “Two”. BROKEN!

ResultActivity.java

public class ResultActivity extends Activity {
    String title = null;
    TextView text;

    int i=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity);
        text = (TextView) findViewById(R.id.textView1);



        title = getIntent().getStringExtra("title");
         i = getIntent().getIntExtra("uid", 0);


        text.setText(title);

    }
  • 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-13T10:08:41+00:00Added an answer on June 13, 2026 at 10:08 am

    You create multiple intents that are mixed. I cleaned up the code (but did not test it)

        NotificationManager nm = (NotificationManager) ctx
                .getSystemService(Context.NOTIFICATION_SERVICE);
    
        Resources res = ctx.getResources();
    
        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(this, ResultActivity.class);
        String pass = text.getText().toString();
        resultIntent.setData(new Uri.Builder().scheme("data")
                .appendQueryParameter("text", "my text").build());
        resultIntent.putExtra("title", pass);
        resultIntent.putExtra("uid", i);
    
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(ResultActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);
    
        NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
        builder.setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(
                        BitmapFactory.decodeResource(res,
                                R.drawable.ic_launcher))
                .setTicker("Remember to " + text.getText())
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle(text.getText())
                .setContentIntent(resultPendingIntent);
    
        Notification n = builder.build();
        n.flags = Notification.FLAG_NO_CLEAR;
        nm.notify(i++, n);
    
        text.setText(null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I want to have a simple web app that takes some user input,
I have a fairly simple app that launches the camera from a menu. The
Let's say I have a fairly simple app that lets users store information on
I have a fairly simple web app that uses cookies to store some information
I have a fairly simple android app, it gets protobuf data from a web
I have a fairly simple console app that monitors an exchange mailbox, picks particular
I have a fairly simple iPhone app that downloads a set of UITableView results
I have a fairly simple MFC app that just defines its own sub-classes of
I have a fairly simple python loop that calls a few functions, and writes
I have a fairly simple Linq query (simplified code): dim x = From Product

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.