标签:android sim ima receive use login code har final
EventBus is a publish/subscribe event bus for Android
EventBus...
In your build.gradle :
dependencies {
compile ‘org.greenrobot:eventbus:3.0.0‘
}
package com.netcircle.myeventbusdemo;
/**
* Created by sweetgirl on 2017/11/27
*/
public class UserMessage {
public final String mName ;
public final String mPassword;
public UserMessage(String name, String password){
this.mName = name;
this.mPassword = password;
}
}
package com.netcircle.myeventbusdemo;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private EditText input_name;
private EditText input_password;
private Button btn_login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
initView();
}
private void initView(){
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.tv_signup);
input_name = (EditText) findViewById(R.id.input_name);
input_password = (EditText) findViewById(R.id.input_password);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(intent);
}
});
}
@Subscribe
public void onMessageEvent(UserMessage event) {
Toast.makeText(MainActivity.this,"MainActivity"+event.mName+event.mPassword,Toast.LENGTH_SHORT).show();
Log.i("MainActivity"+event.mName,"MainActivity-psw"+event.mPassword);
}
@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
}
package com.netcircle.myeventbusdemo;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import org.greenrobot.eventbus.EventBus;
public class RegisterActivity extends AppCompatActivity {
private EditText et_input_name;
private EditText et_input_password;
private Button btn_registered;
private String name;
private String psw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
et_input_name = (EditText) findViewById(R.id.et_input_name);
et_input_password = (EditText) findViewById(R.id.et_input_password);
btn_registered = (Button) findViewById(R.id.btn_registered);
name = et_input_name.getText().toString();
psw = et_input_password.getText().toString();
btn_registered.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
name = et_input_name.getText().toString();
psw = et_input_password.getText().toString();
Log.i("RegisterActivity-name"+name,"RegisterActivity-psw"+psw);
EventBus.getDefault().post(new UserMessage(name,psw));
Intent intent = new Intent(RegisterActivity.this,MainActivity.class);
startActivity(intent);
}
});
}
}
see Log
11-28 10:39:05.656 25999-25999/com.netcircle.myeventbusdemo I/RegisterActivity-name123: RegisterActivity-pswqwe
11-28 10:39:05.676 25999-25999/com.netcircle.myeventbusdemo I/MainActivity123: MainActivity-pswqwe
EventBus - Android's Event Bus
标签:android sim ima receive use login code har final
原文地址:http://www.cnblogs.com/chenxiaoyan/p/7908400.html