Android Sample : start a child activity from main activity
The sample application will explain that how to start the child activity from the main activity.
Create an android project in eclipse. The main activity will be create by default by the wizard.
Modify the default activity class as follows
Android Sample - ActivitySample: ActivitySample is an android sample for explaining the android activity life cycle.
Step 1 : Create a android project in eclipse with any name or “ActivitySample”.
Once the sample created explore the project src and open the activity class
The main activity class is generated by wizard for the application. Add the highlighted code.
The main activity class is generated by wizard for the application. Add the highlighted code.
package com.creativeandroidapps.SampleActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class ActivitySampleActivity extends Activity {
/** Called when the activity is first created. */
private static final String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(TAG, "Activity Life Cycle : onCreate : Activity Created");
}
}
Now add the following life cycle methods
@Override
protected void onStart() {
super.onStart();
Log.i(TAG,"Activity Life Cycle : onStart : Activity Started");
}
@Override
protected void onResume() {
super.onResume();
Log.i(TAG,"Activity Life Cycle : onResume : Activity Resumed");
}
@Override
protected void onPause() {
super.onPause();
Log.i(TAG,"Activity Life Cycle : onPause : Activity Paused");
}
@Override
protected void onStop() {
super.onStop();
Log.i(TAG,"Activity Life Cycle : onStop : Activity Stoped");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG,"Activity Life Cycle : onDestroy : Activity Destroyed");
}
open the res->layout->main.xml file and add a button in the layout view
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="onPlayButton"/>
open the main activity file and add the function for the button
public void onPlayButton(View view)
{
Intent done = new Intent(ActivitySampleActivity.this, ChildActivity.class);
startActivity(done);
Log.i(TAG,"Button Pressed : Starting Child Activity");
}
Now add a new layout for the child activity in res->layout. Right click and add new android layout file.
Add a Layout File |
open the xml file or graphical layout and add the following layout
<?xml version="1.0" encoding="utf-8"?>
<RatingBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RatingBar>
This is just adding a rating bar
Now add a class ChildActivity by right click on the package in the Package Explorer.
Add a JAVA class |
open the class file and add the following code
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class ChildActivity extends Activity {
private static final String TAG = "ChildActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.child);
Log.i(TAG,"Activity Life Cycle : onCreate : Activity Created");
}
@Override
protected void onStart() {
super.onStart();
Log.i(TAG,"Activity Life Cycle : onStart : Activity Started");
}
@Override
protected void onResume() {
super.onResume();
Log.i(TAG,"Activity Life Cycle : onResume : Activity Resumed");
}
@Override
protected void onPause() {
super.onPause();
Log.i(TAG,"Activity Life Cycle : onPause : Activity Paused");
}
@Override
protected void onStop() {
super.onStop();
Log.i(TAG,"Activity Life Cycle : onStop : Activity Stoped");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG,"Activity Life Cycle : onDestroy : Activity Destroyed");
}
}
Thank you! I did not do this all literally, but the suggested recipes work ok! Thank you again.
ReplyDeleteYour blog has given me that thing which I never expect to get from all over the websites. Nice post guys!
ReplyDelete
ReplyDeleteGreat Article
Android Final Year Project Ideas for Computer Science
Project Centers in Chennai
Antalya
ReplyDeleteTrabzon
Niğde
Maraş
Antep
1A8O
Muğla
ReplyDeleteBitlis
Karaman
GYCQWC
Isparta
ReplyDeleteTunceli
Yozgat
Çorum
Konya
KAGCY
Bursa
ReplyDeleteKırşehir
Muş
Mersin
Çanakkale
1CDT0
Bayburt
ReplyDeleteKars
Batman
Urfa
İzmir
JJQZ
Ağrı
ReplyDeleteDiyarbakır
Bolu
Elazığ
Siirt
80MHA
Samsun
ReplyDeleteNevşehir
Van
Bartın
Edirne
JXİ
İstanbul
ReplyDeleteSivas
Kırıkkale
Zonguldak
Iğdır
5CR
Aksaray
ReplyDeleteAydın
Kütahya
Rize
Bingöl
FRP14
Uşak
ReplyDeleteAnkara
Adıyaman
Hatay
Şırnak
PLY3VT
https://bayanlarsitesi.com/
ReplyDeleteTokat
Kastamonu
Tekirdağ
Gümüşhane
ASL
Mardin
ReplyDeleteistanbul
Çanakkale
Antep
Elazığ
QQİS00
whatsapp görüntülü show
ReplyDeleteücretli.show
X5WATO
C0679
ReplyDeleteŞırnak Lojistik
Karaman Şehirler Arası Nakliyat
Adıyaman Şehirler Arası Nakliyat
Yenimahalle Fayans Ustası
Gümüşhane Şehir İçi Nakliyat
Bitlis Şehirler Arası Nakliyat
Elazığ Parça Eşya Taşıma
Karapürçek Fayans Ustası
Altındağ Boya Ustası
9DEAB
ReplyDeleteMersin Parça Eşya Taşıma
Çerkezköy Halı Yıkama
Sincan Fayans Ustası
Çerkezköy Bulaşık Makinesi Tamircisi
Çanakkale Şehirler Arası Nakliyat
Kilis Lojistik
Samsun Şehir İçi Nakliyat
Bursa Şehir İçi Nakliyat
Manisa Şehirler Arası Nakliyat
63806
ReplyDeleteTrabzon Parça Eşya Taşıma
Siirt Parça Eşya Taşıma
Amasya Evden Eve Nakliyat
Kırklareli Lojistik
Ünye Çatı Ustası
Ardahan Şehirler Arası Nakliyat
Aydın Şehir İçi Nakliyat
Van Parça Eşya Taşıma
İzmir Şehir İçi Nakliyat
26C71
ReplyDeleteKırşehir Ücretsiz Sohbet Uygulaması
kızlarla canlı sohbet
bedava sohbet
kırıkkale telefonda kızlarla sohbet
zonguldak sohbet odaları
çorum bedava sohbet odaları
Sakarya Görüntülü Sohbet Uygulama
çanakkale canlı sohbet uygulamaları
malatya canlı sohbet siteleri
46EEE
ReplyDeleteen iyi rastgele görüntülü sohbet
Bilecik Canlı Sohbet Odaları
bursa rastgele canlı sohbet
canlı ücretsiz sohbet
adana sesli görüntülü sohbet
amasya kadınlarla rastgele sohbet
Giresun Bedava Görüntülü Sohbet
ücretsiz sohbet uygulamaları
bitlis rastgele sohbet
6FBCC
ReplyDeleteYeni Çıkacak Coin Nasıl Alınır
Bitcoin Çıkarma
Görüntülü Sohbet
Bitcoin Nasıl Üretilir
Lovely Coin Hangi Borsada
Bitcoin Kazanma
Linkedin Beğeni Satın Al
Mexc Borsası Güvenilir mi
Onlyfans Takipçi Hilesi
شركة عزل اسطح بحائل nhGgTgnO1E
ReplyDeleteشركة تسليك مجاري بالدمام 2E291k2Ak3
ReplyDelete