Please try entering the code below. He will decide your flight.
Follow the instructions below.
1) Make one BaseActivity Class. 2) Make One MainActivity Class and extend BaseActivity. 3) Make another SecondActivity class and extend BaseActivity.
Here I post all the classes you need.
What am I doing in BaseActivity?
I am creating one countdown timer class called MyCount that will display the remaining time. I create one boolean flag that sets false to default. therefore, when the user calls the setHeading () function of the BaseActivity function, he will check the falg if it is false, then start the timer, and if it is true then set the timer again and run again.
Baseactivity
import android.app.Activity; import android.os.Bundle; import android.os.CountDownTimer; import android.widget.TextView; public abstract class BaseActivity extends Activity { private TextView textView = null; public static MyCount counter = null; private static boolean flag = false; private static long millisUntilFinishedVariable = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } protected void setHeading(String message) { if(textView == null) { textView = (TextView)findViewById(R.id.textView); if(textView != null) textView.setText(message); if(flag == false) { counter = new MyCount(30000, 1000); counter.start(); } else { counter.cancel(); counter = new MyCount(millisUntilFinishedVariable, 1000); counter.start(); } } }
Mainactivity
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends BaseActivity { private Button buttonClick = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setHeading("Text From Main Activity"); buttonClick = (Button)findViewById(R.id.buttonClick); buttonClick.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { startActivityForResult(new Intent(MainActivity.this,SecondActivity.class), 0); } }); } }
activity_main.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" > <include layout="@layout/header"/> <Button android:id="@+id/buttonClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="96dp" android:layout_marginTop="68dp" android:text="Second Activity" /> </RelativeLayout>
Secondactivity
import android.os.Bundle; public class SecondActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_activity); setHeading("From Second Activity"); } }
second_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" > <include layout="@layout/header"/> </RelativeLayout>
header.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="18.0sp"/> </LinearLayout>