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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:12:02+00:00 2026-06-15T11:12:02+00:00

My app creates a Notification from an IntentService . When tapped, the Notification opens

  • 0

My app creates a Notification from an IntentService. When tapped, the Notification opens MainActivity of type Activity. MainActivity's onCreate() method is called every time a newNotification is tapped, irrespective of whether an instance ofMainActivity is already created or not. Tapping the Notification always creates a new instance that replaces the old one.

Is there a way to call onCreate() only if the Activity doesn’t exist and call e.g. onNewIntent() if MainActivity already exists (or another appropriate method) ?

The Notification is currently created like this:

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(com.exampleapp.myclient.R.drawable.dummy_notification_icon, "Notification!", System.currentTimeMillis());
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setLatestEventInfo(context, notificationTitle, "test", pendingIntent);
    notificationManager.notify(1, notification);

MainActivity in Manifest:

<activity android:name="com.exampleapp.myclient.MainActivity"  
    singleTop="true">
 </activity>
  • 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-15T11:12:04+00:00Added an answer on June 15, 2026 at 11:12 am

    Your simply looking for the android:launchmode attribute in the manifest. For your case it should be set to singleTask. Then you’ll be able to handle the onNewIntent(); and you’ll only have 1 instance.

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

Sidebar

Related Questions

Since http is stateless, every request to an app creates a new object. How
I have an activity that creates notifications using the following code: Notification notification =
I managed to get a notification from our app to appear on the Notification
Every time I log on to my server through SSH I need to type
In my app that creates an notification icon, the click on this icon launches
I need to send a distributed notification from my cocoa app to my firebreath
Long time reader, first time poster here. I'm creating a test app that creates
I have a click-once deployed app that uses a notification icon created using the
My App creates a form, and saves it as a html file on SD
I have an app that creates a variable number of ScatterviewItems based on which

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.