Question
Could you please help me on these Android Studio Mobile Application Problem. I appreciate your help. This is different than the first one I submitted
Could you please help me on these Android Studio Mobile Application Problem. I appreciate your help. This is different than the first one I submitted
Review and test the app
1. Start Android Studio and open the following project
1. Review the code for this app. Note that it uses a timer and a timer task to update the user interface every second.
1. Run the app. When it starts, it should display the number of seconds since the app started.
Modify the timer
2. Add an onPause method that cancels the timer when the app is paused.
3. Add Start and Stop buttons that allow the user to start and stop the timer.
4. Modify the timer so it only executes the timer task every 10 seconds.
Modify the timer task and update the UI
5. Add code to the timer task that downloads the RSS feed described in chapter 10. Since the timer task runs in its own thread, you dont need to use an AsyncTask class to do this.
6. Modify the code that updates the user interface so it displays a message that indicates the number of times that the app has downloaded the RSS feed. This message should be formatted like this:
Main_Activity xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/messageTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="17dp" android:layout_marginTop="14dp" android:text="@string/hello_world" android:textSize="20sp" /> RelativeLayout>
_________________________________________________________________________
Java File
package com.murach.ch10_ex5; import java.util.Timer; import java.util.TimerTask; import android.os.Bundle; import android.app.Activity; import android.widget.TextView; public class MainActivity extends Activity { private TextView messageTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); messageTextView = (TextView) findViewById(R.id.messageTextView); startTimer(); } private void startTimer() { final long startMillis = System.currentTimeMillis(); Timer timer = new Timer(true); TimerTask task = new TimerTask() { @Override public void run() { long elapsedMillis = System.currentTimeMillis() - startMillis; updateView(elapsedMillis); } }; timer.schedule(task, 0, 1000); } private void updateView(final long elapsedMillis) { // UI changes need to be run on the UI thread messageTextView.post(new Runnable() { int elapsedSeconds = (int) elapsedMillis/1000; @Override public void run() { messageTextView.setText("Seconds: " + elapsedSeconds); } }); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started