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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:13:48+00:00 2026-06-08T18:13:48+00:00

i have maybe a stupid/strange question i am new to android and java and

  • 0

i have maybe a stupid/strange question

i am new to android and java and i need some advice to understand the methods of android and how to use them

i have a main activity class that looks like this

extends  Activity implements OnClickListener{

     private static final String TAG = "ServicesDemo";
     public String myimageURL;
     private EditText Lyrics;
    private ImageView AlbumPic;
    private Button play,  stop;
    private TextView Artist, Song, Album, News, Lyric;
    private UpdateTimeTask m_updateTime;
    private Handler m_handler;
    Parser data;
    /** The delay in milliseconds between updates. */
    private final int DELAY = 20000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Artist =(TextView)findViewById(R.id.tvArtist);
        Song  =(TextView)findViewById(R.id.tvSongTitle);
        Album =(TextView)findViewById(R.id.tvAlbum);
        play = (Button) findViewById(R.id.play);
        stop = (Button) findViewById(R.id.stop);
        Lyrics = (EditText) findViewById(R.id.tvLyrics);
        News = (TextView)findViewById(R.id.tvAnouncement);
        AlbumPic = (ImageView) findViewById(R.id.AlbumPic);



        play.setOnClickListener(this);
        stop.setOnClickListener(this);



        m_updateTime = new UpdateTimeTask();

        m_handler = new Handler();
        m_handler.post(m_updateTime);
    }

    private class UpdateTimeTask implements Runnable {
        public void run() {


            try {

                SAXParserFactory saxPF = SAXParserFactory.newInstance();
                SAXParser saxP = saxPF.newSAXParser();
                XMLReader xmlR = saxP.getXMLReader();


                URL url = new URL("http://www.mysite.com/AndroidTest.php"); 
                XMLHandler myXMLHandler = new XMLHandler();
                xmlR.setContentHandler(myXMLHandler);
                xmlR.parse(new InputSource(url.openStream()));

            } catch (Exception e) {
                System.out.println(e);
            }
            data = XMLHandler.data;



            for (int i = 0; i < data.getTitle().size(); i++) {

           Lyrics.setText(data.getLyric().get(i));
                 myimageURL = data.getPic().get(i);

            Song.setText("Title = "+data.getTitle().get(i));


            Artist.setText("Artist = "+data.getArtist().get(i));


            Album.setText("Album = "+data.getAlbum().get(i)); 






 }

 downloadFile(myimageURL );

}

Bitmap bmImg;
void downloadFile(String fileUrl) {
 URL myFileUrl = null;
 try {
    myFileUrl = new URL(fileUrl);
 } catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
 }
 try {
    HttpURLConnection conn = (HttpURLConnection) myFileUrl
          .openConnection();
    conn.setDoInput(true);
    conn.connect();
    InputStream is = conn.getInputStream();

    bmImg = BitmapFactory.decodeStream(is);
    AlbumPic.setImageBitmap(bmImg);
 } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
 }
 m_handler.postDelayed(m_updateTime, DELAY);
 AlbumPic.clearAnimation();
}

}

the code works ok

as you can see i use a timer and a service

the service code is written in a different class called “my_service”
the timer code is written in the main class

my question is should i put the timer code which i have now in the main class in a separate class for example “timer class”

and then call it from the main class just like i did for the for the service

or is it ok just like it is now

and because the xml is on a internet server should i use asynctask?

did i understood it right that the asynctask only runs once so if i use a asynctask i have to use it in combination with a timer to keep the UI updated

thanks

p.s. is a “thread” the same as a “class”

  • 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-08T18:13:50+00:00Added an answer on June 8, 2026 at 6:13 pm

    I’d leave the timer code it in there, unless you wanted to some major refactoring.

    The reason for this being that you access a number of private members of your main activity in the UpdateTimeTask. Break this out into a separate file, and you will no longer have access to these members in their current state.

    If you’re up for some refactoring, you might be able to make an AsyncTask work. They are used when you want to perform a single task (rather than something like polling), which you’re doing. If you find the AsyncTask to be causing problems, then use a handler to communicate with the UI.

    Finally, threads are not the same as classes in Java. A class represents a set of characteristics and commands for a particular object, whereas a thread represents a path of execution. Class objects are the things that are used to perform actions, whereas threads are certain collections of actions.

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

Sidebar

Related Questions

I have some questions, maybe stupid question. I have this url: http://flibusta.net/opds/opensearch?searchTerm=Тол&searchType=books and I
I'm newbie to WPF, and maybe ask some stupid question. However. I have a
I'am new to jquery and maybe this is a stupid question but I have
A short, maybe stupid question. For classes and structs, sometimes I like to have
Just maybe trivial, maybe stupid question. I have two solutions: 1) The main app
Maybe this is a stupid question but it's bugging me. I have a bi-directional
I'd like to ask you a simple question(maybe stupid one). Would you use Netbeans
maybe this is a stupid question, but i have seen many Tuts that build
Sorry for maybe a stupid question. I have EditTextPreference... How to check is his
Maybe this is a stupid question, but I dont know how to use Membership

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.