简体   繁体   English

Android Intent,如何获得下一个活动?

[英]Android Intent, how to get next activity?

i'am still beginner in android. 我还是android的初学者。 how to make android onclicklistener to next activity, i mean,i make RegisterActivity and when the user has register , the program should be to MainActivity but it goes to SingleMenuItemActivity. 如何使android onclicklistener进入下一个活动,我的意思是,我进行RegisterActivity,当用户注册后,该程序应转到MainActivity,但转到SingleMenuItemActivity。 anyone can tell me what i suppose to do? 谁能告诉我我该怎么办? thank you very much. 非常感谢你。 *sorry for my bad english. *对不起,我的英语不好。

package unai.skripsi.bandungtourgiude;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class SingleMenuItemActivity  extends Activity {

// JSON node keys
private static final String in_nama_tempat = "nama_tempat";
private static final String in_alamat_tempat = "alamat_tempat";
private static final String in_no_tempat = "no_tempat";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_list_item);

    // getting intent data
    Intent in = getIntent();

    // Get JSON values from previous intent
    String nama = in.getStringExtra(in_nama_tempat);
    String alamat = in.getStringExtra(in_alamat_tempat);
    String nomor = in.getStringExtra(in_no_tempat);

    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.nama_tempat);
    TextView lblCost = (TextView) findViewById(R.id.alamat_tempat);
    TextView lblDesc = (TextView) findViewById(R.id.no_tempat);

    lblName.setText(nama);
    lblCost.setText(alamat);
    lblDesc.setText(nomor);

    Button map = (Button) findViewById(R.id.button1);
       map.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(SingleMenuItemActivity.this, Pariwisata.class));
        }
    });

       Button call = (Button) findViewById(R.id.button2);
       call.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(SingleMenuItemActivity.this, Telfon.class));
        }
    });

       Button text = (Button) findViewById(R.id.button3);
       text.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(SingleMenuItemActivity.this, RegisterActivity.class));
        }
    });
}
}

RegisterActivity.java RegisterActivity.java

package unai.skripsi.bandungtourgiude;

import static unai.skripsi.bandungtourgiude.CommonUtilities.SENDER_ID;
import static unai.skripsi.bandungtourgiude.CommonUtilities.SERVER_URL;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RegisterActivity extends Activity {
// alert dialog manager
AlertDialogManager alert = new AlertDialogManager();

// Internet detector
ConnectionDetector cd;

// UI elements
EditText txtName;
EditText txtEmail;

// Register button
Button btnRegister;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
        // Internet Connection is not present
        alert.showAlertDialog(RegisterActivity.this,
                "Internet Connection Error",
                "Please connect to working Internet connection", false);
        // stop executing code by return
        return;
    }

    // Check if GCM configuration is set
    if (SERVER_URL == null || SENDER_ID == null || SERVER_URL.length() == 0
            || SENDER_ID.length() == 0) {
        // GCM sernder id / server url is missing
        alert.showAlertDialog(RegisterActivity.this, "Configuration Error!",
                "Please set your Server URL and GCM Sender ID", false);
        // stop executing code by return
         return;
    }

    txtName = (EditText) findViewById(R.id.txtName);
    txtEmail = (EditText) findViewById(R.id.txtEmail);
    btnRegister = (Button) findViewById(R.id.btnRegister);

    /*
     * Click event on Register button
     * */
    btnRegister.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // Read EditText dat
            String name = txtName.getText().toString();
            String email = txtEmail.getText().toString();

            // Check if user filled the form
            if(name.trim().length() > 0 && email.trim().length() > 0){
                // Launch Main Activity
                Intent i = new Intent(getApplicationContext(), MainActivity.class);

                // Registering user on our server                   
                // Sending registraiton details to MainActivity
                i.putExtra("name", name);
                i.putExtra("email", email);
                startActivity(i);
                finish();
            }else{
                // user doen't filled that data
                // ask him to fill the form
                alert.showAlertDialog(RegisterActivity.this, "Registration Error!", "Please enter your details", false);
            }
        }
    });
}

}

my AndroidManifest 我的AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="unai.skripsi.bandungtourgiude"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<permission
    android:name="unai.skripsi.bandungtourguide.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<uses-permission android:name="unai.skripsi.bandungtourguide.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>

<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
    android:name="unai.skripsi.bandungtourgiude.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="unai.skripsi.bandungtourgiude.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">
    <activity
        android:name="unai.skripsi.bandungtourgiude.DashboardActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateHidden" >


        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <activity
        android:name=".RegisterActivity"
        android:label="@string/app_name"></activity>

     <!-- Main Activity -->
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/app_name" >
    </activity>

    <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="unai.skripsi.bandungtourgiude" />
        </intent-filter>
    </receiver>

    <service android:name=".GCMIntentService" />

    <!--  Login Activity -->
    <activity
        android:label="Silahkan login"
        android:name=".Fungsilogin"></activity>

    <!--  Register Activity -->
    <activity
        android:label="Silahkan mendaftar"
        android:name=".Pendaftaran"></activity>

    <activity
        android:label="tes"
        android:name=".TesAsyncTaskActivity"></activity>

    <activity
        android:label="PILIHAN TEMPAT"
        android:name=".SingleMenuItemActivity"></activity>

    <activity
        android:label="rumah sakit"
        android:name=".RumahSakit"></activity>

    <activity
        android:label="hotel"
        android:name=".Hotel"></activity>
    <activity
        android:label="ATM"
        android:name=".Atm"></activity>
    <activity
        android:label="PARIWISATA"
        android:name=".Pariwisata"></activity>
     <activity
        android:label="KANTOR POLISI"
        android:name=".Polisi"></activity>
      <activity
        android:label="KULINER"
        android:name=".Kuliner"></activity>
       <activity
        android:label="OUTLET"
        android:name=".Outlet"></activity>
       <activity
        android:label="OUTLET"
        android:name=".Map"></activity>

    <activity
        android:label="rumah sakit"
        android:name=".Semuatempat"></activity>

    <activity
        android:label="Telfon operator"
        android:name=".Telfon"></activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAkJYisD9-6HB8D1asdeTTTZVtgNCLg8Fyk" />

</application>

</manifest>

Intent filter determines what gets launched. 意图过滤器确定启动什么。

Change your manifest as follows 如下更改清单

<activity
    android:name=".MainActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/app_name" >

<intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

and remove 并删除

<intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

from Dashboard activity. 来自资讯主页活动。 HTH. HTH。

In your btnRegister onClick listener, remove startActivity and finish . 在您的btnRegister onClick侦听器中,删除startActivity完成

Intent i = new Intent(getApplicationContext(), MainActivity.class);
// Registering user on our server                   
// Sending registraiton details to MainActivity
i.putExtra("name", name);
i.putExtra("email", email);
RegisterActivity.this.startActivity(i);

If you don't want RegisterActivity in the history stack, set attribute android:noHistory=true for the activity tag in your manifest file instead of finish() method. 如果您不希望在历史记录堆栈中使用RegisterActivity,请为清单文件中的活动标记(而不是finish()方法)设置属性android:noHistory=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android中使用Intent调用下一个活动的方法 - How to use intent to call the method of next activity in android RecyclerView列表和下一个活动Android的意图 - RecyclerView List and intent to next activity Android Android-检查数组是否具有此值,获取位置并发送多余的意图到下一个活动片段 - Android - Check whether the array has this value , get the position and send intent put extra to next activity fragment 如何在Android中获取非活动类的Intent值 - How to get Intent values non Activity Class in Android 如何在选定的列表视图项中获取ID以打开上下文菜单并通过下一个活动进行意图? - How to get the id in selected listview item to open contextmenu and intent thru pass the next activity.? 如何在Android中的单击功能的下一个活动中获取href路径 - how to get href path in next activity on click function in Android 如何在不调用android中的startactivity的情况下进行意图活动? - How intent activity without calling the startactivity in android? 如何从 Intent Android 调用相同的活动? - how to call same activity from Intent Android? Intent.putExtra-如何将字符串发送到下一个活动? - Intent.putExtra - How to send a string to the next activity? 如何从 Activity 获取 Intent 数据到 Fragment - How to get Intent Data from Activity into Fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM