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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:28:32+00:00 2026-06-03T20:28:32+00:00

So here’s the deal. I created a user defined class. It contains a method

  • 0

So here’s the deal.

I created a user defined class. It contains a method which returns a notification object. Now I want this method to be a little bit flexible. Like pass the activity which will open when the user clicks the notification in the notification bar. Here’s the method

public Notification getUserNotificationObject(String status, String message, String tickerText, boolean isOngoingEvent){
    Notification notification = new Notification(R.drawable.image, tickerText, System.currentTimeMillis());

    long vibInterval =  (long) context.getResources().getInteger(R.integer.vibrateInterval);

    notification.vibrate = new long[] {vibInterval, vibInterval, vibInterval, vibInterval, vibInterval};

    Intent notifyIntent = new Intent(context, HomeScreen.class);
    CharSequence contentTitle = "Title";
    CharSequence contentText = status + "-" + message;
    notification.setLatestEventInfo(context, contentTitle, contentText, PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    notification.ledARGB = Color.argb(100, 0, 254, 0);
    notification.ledOnMS = 500;
    notification.ledOffMS = 500;        
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    if(isOngoingEvent){
         notification.flags |= Notification.FLAG_ONGOING_EVENT;
    }

    return notification;
}

I want to be able to pass the activity as a parameter in this instead of the

HomeScreen.class

used above in intent definition (for giving additional control to the user of this class (or other developers) to select which activity to open when notification is clicked). I tried using Activity as one of the parameters for this method, but whenever I tried passing another activity while calling this method like “Activity2” or “Activity2.this” it gives me error saying:

No enclosing instance of the type Activity2 is accessible in scope

Is there any work-around for this or any way to pass the activity as a parameter. Or should I just differentiate those based on NotificationID.

Any help in this regard or any correction in the code above is welcome. (“context” is a class level variable so don’t worry about that. This piece of code is working fine).

  • 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-03T20:28:34+00:00Added an answer on June 3, 2026 at 8:28 pm

    The type of HomeScreen.class is Class. So you could pass an instance of a Class to indicate the next activity. For example (formatted for readability):

    public Notification getUserNotificationObject(
        String status,
        String message,
        String tickerText,
        boolean isOngoingEvent,
        Class nextActivityClass) {
    

    and call with:

    getUserNotificationObject(..., HomeScreen.class)
    

    More flexible, though, might be to pass an Intent to your function. That way, the caller can create the Intent in the way they want, and would allow them to add additional data to the intent if they need to. Creating a new Intent inside your function does not permit that flexibility.

    public Notification getUserNotificationObject(
        String status,
        String message,
        String tickerText,
        boolean isOngoingEvent,
        Intent nextIntent) {
    

    and call with:

    Intent intent = new Intent(context, HomeScreen.class);
    getUserNotificationObject(..., intent)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the method. I want to know if I am violating any best practices
Here's the problem....I have three components...A Page that contains a User Control and a
Here's the situation, i want to have a user that can enter time on
Here's my situation: I have a Data Template set up which contains a ToggleButton
Here is what I want: <h3 class=ExpressCheckoutTitle> <a onclick= href=# class=ChangeLink>Modify »</a> Step 4:
Here is a complete example. I want to forbid using A::set from objects casted
Here's the deal: I'm in the process of planning a mid-sized business application that
Here's what I want to do: Given a table PeopleOutfit (id int primary key,
Here's a Clone() implementation for my class: MyClass^ Clone(){ return gcnew MyClass(this->member1, this->member2); }
Here's my scenario: <!-- Normal Control --> <div class=required> <label for=address1>Address line 1</label> <input

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.