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

The Archive Base Latest Questions

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

I am using following code in service to open the main/launcher Activity , the

  • 0

I am using following code in service to open the main/launcher Activity , the code worked fine until I declared this project as library and created two other projects which use this library.

So in the onStartCommand of service this code is written.

 final Notification notification = new Notification(R.drawable.ic_launcher, null, 0);   

    String notifTitle = "Service";
    String notifMessage = "Running";

    final Intent notificationIntent = new Intent(this,   MainActivity.class);
    notificationIntent.putExtra("extra", "value");
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.setAction("android.intent.action.MAIN");
    notificationIntent.addCategory("android.intent.category.LAUNCHER");

    final PendingIntent contentIntent = PendingIntent
                            .getActivity(this, 0, notificationIntent,0);



    notification.setLatestEventInfo(this, notifTitle, notifMessage, contentIntent);     
    startForeground(17, notification);

MainActivity.class is part of library, two projects which use this library have their main Activities MainActivityA , MainActivityB which extend MainActivity of library.

Now the problem is when I click notification of service, MainActivityA or MainActivityB should be launched but right now nothing happens, but previously it worked when library was a project itself

Any ideas would be appreaciated alot ,

Thank you,

  • 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-14T21:32:11+00:00Added an answer on June 14, 2026 at 9:32 pm

    There are a couple of ways to go about this.

    You could declare an Intent Filter on an Activity in your manifest and broadcast the Intent, but this could be problematic if the user has both versions installed on their device. (There is a local broadcast in the support library that you could use instead docs)

    Personally I would use Android’s resource system to load the class name dynamically. Intents give you that ability to set the ComponentName which is the same thing as giving it a hardcoded reference the an Activity’s class.

    Intent i = new Intent();
    String mPackage = ctx.getPackageName();
    String mClass = ctx.getResources().getString(R.string.notification_class_name);
    i.setComponent(new ComponentName(mPackage,mPackage+mClass));
    

    The library project’s values can be overridden by the projects that use them, so in both of these projects you have a value in strings.xml that corresponds to that app’s notification activity.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="notification_class_name">.MainActivityA</string>
    </resources>
    

    You can then use this Intent with your pendingIntent and it will open the activity inside of the current application.

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

Sidebar

Related Questions

I'm using the following code and an open service provided by wordpress to grab
I am using the following code to invoke the http://www.highoncoding.com/Customers.asmx web service. UPDATE 1:
I am using following code to show a spinning wheel: $(#loading) .hide() .ajaxStart(function(){ $(this).show();
I am using following code to get bitmap from url. This function is used
I'm creating an application with its main window hidden by using the following code:
I am trying to open pdf file in browser using the following code snippet:
I am using following code to get notifications from a service nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
I have the following code which I'm using to populate form fields. This code
Using following code I try to get updated list of checkbuttons' corresponding text values,
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>

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.