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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:37:45+00:00 2026-06-16T22:37:45+00:00

I am trying to send extras through an intent to a service which then

  • 0

I am trying to send extras through an intent to a service which then opens an activity that should receive the intent’s extras. The extras appear to be null in the second activity when I look for them,

here are snippets of the code.

ToDoActivity.java snippet (ACTIVITY)

public void sendNotification(String title, String body){
        Calendar c= Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
        c.set(mYear, mMonth, mDay, mhour, mminute, 0);


        Intent intent = new Intent(this, MyAlarmService.class);
        intent.putExtra(TO_DO_ITEM, body);
        intent.putExtra(TO_DO_NAME, title);
        intent.putExtra(TO_DO_TIME, c.getTimeInMillis());
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        PendingIntent mAlarmSender = PendingIntent.getService(ToDoActivity.this,  0, intent, 0);

        AlarmManager alm = (AlarmManager)getSystemService(ALARM_SERVICE);

        alm.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), mAlarmSender);
        Toast.makeText(this, "Alarm has been set for: " + body, Toast.LENGTH_LONG).show();

    }

MyAlarmService.java (SERVICE)

@Override
    public int onStartCommand(Intent intent, int flags, int startId){
        super.onStartCommand(intent, flags, startId);

        Intent alert = new Intent();
        try{
            alert.putExtras(intent);
        }catch(NullPointerException npe){

        }

        alert.setClass(this, Alert.class);
        alert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(alert);

        return START_REDELIVER_INTENT;
    }

Alert.java Snippets (ACTIVITY)

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);


    Builder alert = new AlertDialog.Builder(this);

    Intent i = new Intent();

    Bundle b = savedInstanceState;
    String title="";
    String itemToDo="";
    long time =0;
    try{
        title = b.getString(ToDoActivity.TO_DO_NAME);
        itemToDo = b.getString(ToDoActivity.TO_DO_ITEM);
        time = b.getLong(ToDoActivity.TO_DO_TIME);
    }catch (NullPointerException npe){
        try{
            title = i.getStringExtra(ToDoActivity.TO_DO_NAME);
            itemToDo = i.getStringExtra(ToDoActivity.TO_DO_ITEM);
            time = i.getLongExtra(ToDoActivity.TO_DO_TIME, System.currentTimeMillis());

        }catch(NullPointerException npe2){

        }
    }
    if((!title.equals("") && !itemToDo.equals("") && time !=0))
        makeNotif(title, itemToDo, time);
    alert.setTitle("Alert: Do the item on your to do list!!");
    if(!itemToDo.equals(""))
        alert.setMessage(itemToDo);
    else
        alert.setMessage("There is an item on your To Do List that needs to get done, please check the list and the time");
    alert.setPositiveButton("OK", new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mp.stop();
            finish();

        }
    });


    playSound(this, getAlarmUri());
    alert.setIcon(R.drawable.ic_launcher);

    AlertDialog ad = alert.create();
    ad.show();

}

This method is in Alert to create a notification (Another issue pertaining to the extras) The info is not being shown through here either (Since I pass info from the previous method to here)

static final int uniqueid= 139686;
    public void makeNotif(String title, String body, long timeInMil){
        try{
            NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            Intent intent = new Intent(this, ToDoActivity.class);

            final String itemToDo=intent.getStringExtra("TDL");
            //          final String title = b.getString("Name");
            final String titleA = intent.getStringExtra("Name");
            //          final long time = b.getLong("Time");
            final long time =intent.getLongExtra("Time",0);

            PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
            //Notification n = new Notification(0, body, System.currentTimeMillis());

            //Notifaction n = Notification

            Notification n = new Notification.Builder(this)
            .setContentTitle(title)
            .setContentText(body)
            //.setContentTitle(titleA)
            //.setContentText(itemToDo)
            .setSmallIcon(R.drawable.ic_launcher)
            .setWhen(timeInMil)
            .build();


            //n.setLatestEventInfo(this, title, body, pi);
            n.defaults=Notification.DEFAULT_ALL;
            n.flags = Notification.FLAG_AUTO_CANCEL;
            nm.notify(uniqueid, n);

        }catch(Exception e){
            e.printStackTrace();
        }

    }

If someone could please inform me on why my extras aren’t being transferred over, that would be great.

Thanks,
Vnge

  • 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-16T22:37:47+00:00Added an answer on June 16, 2026 at 10:37 pm

    Change your MyAlarmService onStartCommand method as for sending received intent value to Alert Activity :

    @Override
        public int onStartCommand(Intent intent, int flags, int startId){
            super.onStartCommand(intent, flags, startId);
    
            Intent alert = new Intent();
            try{
                alert.putExtra(TO_DO_ITEM, intent.getExtras().getString(TO_DO_ITEM));
                alert.putExtra(TO_DO_NAME, intent.getExtras().getString(TO_DO_NAME));
                alert.putExtra(TO_DO_TIME, intent.getExtras().getLong(TO_DO_TIME));
            }catch(NullPointerException npe){
    
            }
    

    and use getIntent().getExtras() for receiving intent in Activity instead of savedInstanceState in Alert activity as:

    Bundle b = getIntent().getExtras();
    
     if(b !=null){
     title = b.getString(TO_DO_ITEM);
     itemToDo = b.getString(TO_DO_NAME);
     time = b.getLong(TO_DO_TIME);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send some extras to the next activity, but it simply does
Trying to send a complex type between two systems that have the same code
What I'm trying to do is send an object through Intents; I've been looking
short summary: I am trying to create a program that will send keyboard events
I am trying to send information from notification to invoked activity, while from my
I receive the following Exception while trying to send an email (using Seam) Caused
I'm trying to send via PendingIntent some extra data, like: MyMessage message; //... Intent
i am trying to send an e-mail with multiple attachments. Intent emailIntent = new
I'm trying to accomplish something that should be rather basic in CSS but I'm
i'm trying to send a byte[] from one activity to another. in the recieving

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.