Android筆記——不同apk之間傳遞引數與資料
android程式設計的時候,有時候需要在不同的apk之間傳遞引數或資料,下面是一個簡單的例子:
APK(1)的程式程式碼:
IntentSend.java:
package com.is;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class IntentSend extends Activity {
Channel channel = new Channel();
Button szws;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
szws = (Button)findViewById(R.id.szws);
szws.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("channel", channel.channels[0]);
intent.setClassName("com.bget", "com.bget.BinderGET");
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}
Channel.java:
package com.is;
public class Channel {
String channels[] = {
"深圳衛視",
"深圳電視劇",
"深圳都市"
};
}
import android.os.Bundle;
import android.widget.TextView; public class IntentGet extends Activity {
TextView info;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
info =(TextView)findViewById(R.id.info);
Bundle bundle = new Bundle();
bundle = this.getIntent().getExtras();
info.setText("現在播放的是:" + bundle.getString("channel"));
}
}