How to move activities with intents in Android Studio

Android Studio is one of the software The best Android application developer today. This is due to the many features that are supported by Google. In the previous tutorial, we discussed how to connect Android Studio to Firebase and add data to Firebase. This time we will discuss how to move activity through the use intention in the Android studio.

Also read:

Tutorials

Reference material: Android Guide

1. In this tutorial we will separate the added functions Username and delete Username become two activity. Then second activity is linked to Intentions.

Copy Main activity and Insert in com.example.

Create a name activity the new.

2. Then, Copy Even Activity_main.xml and glue in place Layouts.

Then don’t forget to give it a name.

3. When deleting_activity will be done shape where the user enters Username and if the key is pressed then Username it will be removed from Databases.

delete_activity.xml

Write down the following code xml Clear_activity

              

If the delete key is pressed, then Click method2 is executed.

4. Add activity new to Android manifested.

Write the following code on Android manifest

5. Then continue Main activity User can add user and if you hit the delete key then activity is moved for deletion Activities.

play Activity.xml

Write the following code in xml Main activity.

                         

If the delete key is pressed, then Click method3 is executed. Where method it works to move activity ClearActivities.

6. Add Click2 method At Clearactivity.Java. So that when you press the delete button, the data on Firebase is deleted.

Activity.java. Clear

Write down the following code Great Clearactivity.Java

package com.example.abifirmandhani.inwepo; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase;  public class HapusActivity extends AppCompatActivity {      //instansiasi database firebase     FirebaseDatabase database ;     DatabaseReference myRef;      EditText text4;        @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.hapus_activity);          database = FirebaseDatabase.getInstance();           text4 = (EditText) findViewById(R.id.edit4);        }       //Hapus user     public void Click2(View view){          //inisiasi database reference         myRef = database.getReference("User").child(text4.getText().toString());          //hapus data         myRef.removeValue();       } }

7. Add Click method3 at Great gameactivity.Java so when the method is executed it will be moved activity to Delete activity

MainActivity.java

Write the following code in class gameactivity.Java

package com.example.abifirmandhani.inwepo;  import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView;  import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase;  public class MainActivity extends AppCompatActivity {      //instansiasi database firebase     FirebaseDatabase database ;     DatabaseReference myRef;     EditText text1;     EditText text2;     EditText text3;     EditText text4;        @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          database = FirebaseDatabase.getInstance();          text1 = (EditText) findViewById(R.id.edit1);         text2 = (EditText) findViewById(R.id.edit2);         text3 = (EditText) findViewById(R.id.edit3);         text4 = (EditText) findViewById(R.id.edit4);        }      //method tambah user     public void Click1(View view){          //Referensi database yang dituju         myRef = database.getReference("User").child(text1.getText().toString());          //memberi nilai pada referensi yang dituju          myRef.child("name").setValue(text2.getText().toString());         myRef.child("NoHp").setValue(text3.getText().toString());       }      //Hapus user     public void Click2(View view){          //inisiasi database reference         myRef = database.getReference("User").child(text4.getText().toString());          //hapus data         myRef.removeValue();       }     public void Click3(View v){         Intent intent = new Intent(this, HapusActivity.class);         startActivity(intent);      } }

8. Then when the application is running and the delete key is pressed, then activity will switch to deleteactivity where is the delete function Username.

Application example

Before pressing the delete key:

After pressing the delete key:

Complete.






Leave a Reply

Your email address will not be published.