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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:25:33+00:00 2026-06-12T00:25:33+00:00

I have 2 activities: Activity A – Listview/Adapter Activity B – Radio In activity

  • 0

I have 2 activities:

Activity A – Listview/Adapter

Activity B – Radio

In activity A, I choose a radio and B plays that radio (service).

But everytime that I choose another radio on the list, activity B is instanciated another time and the radio stops and plays again.

Situation example:

# 1 - I'm playing Radio X, I choose X on the list
# 2 - A new instance is created (service is in onCreate() of Activity B)
# 3 - Radio X playing (play() is in onStart() of service)
# 4 - I go back to the list
# 5 - I want to play Radio Y
# 6 - A new instance is created (service is in onCreate() of Activity B)
# 7 - Radio Y playing (play() is in onStart() of service)
# * In onCreate() of service isn't doing nothing

Everything is fine, but what happens if I go back to the list and choose the same radio, for example:

# 1 - Radio Y playing
# 2 - I go back to the list
# 3 - I wanna go to Radio Y again
# 4 - A new instance is created (service is in onCreate() of Activity B) (I don't want this)
# 5 - Radio Y stops and plays again (I don't want this)

I’d like to have a way to check if the radio is playing is the same radio that I wanna go, and don’t create a new instance and don’t stop and play the same radio again.

Edit:

ListView

if (item == "Radio 1"){
       Intent intent = new Intent(getBaseContext(), Radio.class);
       intent.putExtra("radio", "http://test1.com");
       this.startActivity(intent);
} else if (item == "Radio 2"){
       Intent intent = new Intent(getBaseContext(), Radio.class);
       intent.putExtra("radio", "http://test2.com");
       this.startActivity(intent);
}

Radio.java

@Override
public void onCreate(Bundle icicle) {
    requestWindowFeature(Window.FEATURE_LEFT_ICON);
    super.onCreate(icicle);
    setContentView(R.layout.main);

    Intent music = new Intent(getApplicationContext(), Service.class);
    music.putExtra("url", this.getIntent().getStringExtra("radio"));
    startService(music);
}

Service.java

@Override
public void onStart(Intent intent, int startid) {
    Multiplayer m = new MultiPlayer();
    m.playAsync(intent.getExtras().getString("url"));
}
  • 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-12T00:25:34+00:00Added an answer on June 12, 2026 at 12:25 am

    To clarify my answer a bit:

    You have 2 options (depending on :

    Store the playing url in the Service (in onStart) and compare it with the new url being send.

    private String mCurrentUrl;
    
    @Override
    public void onStart(Intent intent, int startid) {    
        String newUrl = intent.getExtras().getString("url");
    
        if ((newUrl.equals(mCurrentUrl)) {
            mCurrentUrl = newUrl;
            Multiplayer m = new MultiPlayer();  
            m.playAsync(mCurrentUrl );
        }
    }
    

    or:

    Define a interface of the Service (AIDL) which retrieves the current radio channel. If you let the activity bind to it you can call this method to retrieve the current channel. Note: that you have to start the Service using startService and then bind to it directly. (Else you Service is killed after your Activity is killed)

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

Sidebar

Related Questions

I have 2 activities. The first activity is an activity that parses JSON data
Assume that we have 3 different activities. Each activity has its own XML file
I have two activities. The first activity display list of the users with short
I have 2 activities. In child activity i have put something like that in
I have two activities. Home activity contain a list view with two buttons named
suppose that you have 3 Activities (A, B and C) and Activity A starts
I'm new to Android. I have two activities. First activity shows selected contact list
I have stack of activities launched after one another. but in one of the
i have 2 activities that share data between them: Activity B (child) @Override public
I have two activities in my Android project: Google Map Activity List Activity I'm

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.