WEB开发网
开发学院手机开发Android 开发 Android 组件复用和进程关系 阅读

Android 组件复用和进程关系

 2010-09-10 01:06:00 来源:WEB开发网   
核心提示:int myProcessID = Process.myPid();//打印当前进程的IDLog.i("---ClientMainActivity", myProcessID + "");}class ClickAction implements OnClickListener{

int myProcessID = Process.myPid();

//打印当前进程的ID

Log.i("---ClientMainActivity----", myProcessID + "");

}

class ClickAction implements OnClickListener{

public void onClick(View v) {

Intent intent = new Intent("com.ostrichmyself.tiantian");

//ComponetName不描述清楚的话, 就无法正确的找到ServerActivity, 但系统提供的Activity,如main都可以为什么?

final ComponentName cn = new ComponentName("com.ostrichmyself","com.ostrichmyself.ServerActivity");

intent.setComponent(cn);

startActivity(intent);

}

}

}

Application2: ServerApk 这个程序有两个Activity, 其一为ServerMainActivity, 其二为ServerActivity, 点击ServerMainActivity, 会对ServerActivity进行调用. ServerActivity 即被调用, 这两个Activity启动的时候, 进程号也会打印出来.

view plaincopy to clipboardprint?

package com.ostrichmyself;

import android.app.Activity;

import android.content.ComponentName;

import android.content.Intent;

import android.os.Bundle;

import android.os.Process;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.TextView;

public class ServerMainActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TextView tv = (TextView)findViewById(R.id.mainTV);

ClickAction l = new ClickAction();

tv.setOnClickListener(l);

int myProcessID = Process.myPid();

Log.i("---ServerMainActivity----", myProcessID + "");

}

class ClickAction implements OnClickListener{

上一页  1 2 3 4 5  下一页

Tags:Android 组件 复用

编辑录入:coldstar [复制链接] [打 印]
赞助商链接