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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:38:13+00:00 2026-05-23T02:38:13+00:00

I have an Activity that plays some audio from within a ListActivity . The

  • 0

I have an Activity that plays some audio from within a ListActivity. The user can also click on the list item and go to a more detailed view of that data. I want the audio to keep playing during that transition from one activity to another and keep playing once the detail activity is active BUT I also need to pause the audio if my activity is being paused or stopped for any other reason.

My issue is that I currently pause the audio in onPause() in the ListActivity because I want the audio to be paused when the user navigates away from my activity. E.g. when they press Home or Back. However, I don’t want the audio to pause when my detailed view activity gets started. onPause() is called in both instances, so how can I distinguish between the two cases?

  • 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-05-23T02:38:14+00:00Added an answer on May 23, 2026 at 2:38 am

    Shouldn’t you be doing that in a service instead? Wouldn’t it be easier? Then you can stop the service when one or another activity is pausing or exiting (depending on which one you want). You could also check if it’s started, and stop accordingly whenever you want.

    Or sorry if I didn’t understand your question. I see you have a lot of points here on SO, so perhaps I’m just confused.

    — edited since your third comment:

    1. A Intent to B: send Intent with name of music.
    2. B onCreate: get name of music from Intent. Set flag x to true.
    3. B onResume: start playing music if from A or resumes from last known position if resuming from B.
    4. B back button: override and set x to false. Actually, you’d cover all points where your activity finishes.
    5. B onPause: stop the music if(x), store last known position of music in memory and stop service.

    Here I assume that you want music to keep playing even when returning to A (that’s what you said, that’s the problem), not just up to B. Setting x is important early on, IMO, because if any other activity (phone call, anything) appears, activity will stop playing the music immediately (user expects that) on onPause. According to Android guidelines, you know that you’re getting back to A only if user presses back button or if you finish() your activity. You can fine tuning checking the position of activities in your task (don’t remember how to do that right now).

    Personally, I also wouldn’t want to resume playback on A (say, B->call->home->A, applying step 3 to A, too), because a disruption in the logical flow of things happens there.

    CAVEAT: I would make sure that there is no other way. I would try to see if you can 1) know in advance which activity is about to be displayed. 2) get any music service to hook up to your task (is that even possible?).

    Anyway, just use my solution if you can’t find a clever way to do that. That would be my suggestion. Good luck.

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

Sidebar

Related Questions

I have an activity that after some user interaction calls finish() on itself. From
i have created a workflow activity that do give the item creater of a
I have an application that will record and play audio files. Some of the
I have an activity that calls the new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to); setListAdapter(notes);
I have an activity that has a TabHost containing a set of TabSpecs each
I have a web-based application that notifies users of activity on the site via
I have a couple of tables which are used to log user activity for
I have some trouble achieving adequate real-time performance from my application and wondering if
I have an activity that extends ViewFactory. The activity does nothing more than act
I have an activity that has properties that look something like this (they're set

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.