android顽皮小球游戏源码

  • 大小:3.02 MB
  • 类型:技术文档
  • 格式:PDF
  • 审核:郜水彤
  • 热度:626
  • 更新:2021-05-07 10:00:59
vip 立即下载( 3.02 MB )
关注公众号免费下载
版权投诉 / 资源反馈(本资源由用户 从菊月 投稿)

为找资料的网友们整理了android游戏源码类学习资源,由濮星河测试纠错,内容涉及到android、顽皮小球、android源码、android游戏源码的内容,已被535人关注,同类资源中评分为8.4分。

android游戏源码资源推荐

资源介绍

【实例截图】

from clipboard

 

from clipboard

package com.bg;
 
import org.jbox2d.collision.AABB;
import org.jbox2d.collision.CircleDef;
import org.jbox2d.collision.PolygonDef;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.ContactListener;
import org.jbox2d.dynamics.World;
import org.jbox2d.dynamics.contacts.ContactPoint;
import org.jbox2d.dynamics.contacts.ContactResult;
 
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceHolder.Callback;
 
public class MySurfaceView extends SurfaceView implements Callback, Runnable, ContactListener {
    private Thread th;
    private SurfaceHolder sfh;
    private Canvas canvas;
    private Paint paint;
    private boolean flag;
    // ----添加一个物理世界---->>
    private final float RATE = 30;// 屏幕到现实世界的比例 30px:1m;
    private World world;// 声明一个物理世界对象
    private AABB aabb;// 声明一个物理世界的范围对象
    private Vec2 gravity;// 声明一个重力向量对象
    private float timeStep = 1f / 60f;// 物理世界模拟的的频率
    private int iterations = 10;// 迭代值,迭代越大模拟越精确,但性能越低
    // 声明小球的Body,便于后续对小球进行操作
    private Body bodyBall;
    //声明胜利与失败的body,用于判定游戏的胜负
    private Body lostBody1, lostBody2, winBody;
    // 声明屏幕宽高
    private int screenW, screenH;
    // 声明游戏状态
    private final int GAMESTATE_MENU = 0;
    private final int GAMESTATE_HELP = 1;
    private final int GAMESTATE_GAMEING = 2;
    private int gameState = GAMESTATE_MENU;
    // 为了游戏暂停时,失败,胜利能继续可能到游戏中的状态,所以并没有将其写成一个状态
    private boolean gameIsPause, gameIsLost, gameIsWin;
    // Body图片资源
    private Bitmap bmpH, bmpS, bmpSh, bmpSs, bmpBall;
    // 菜单、按钮、游戏背景图片资源
    private Bitmap bmpMenu_help, bmpMenu_play, bmpMenu_exit, bmpMenu_resume, bmpMenu_replay, bmp_menubg, bmp_gamebg, bmpMenuBack, bmp_smallbg, bmpMenu_menu,
            bmp_helpbg, bmpBody_lost, bmpBody_win, bmpWinbg, bmpLostbg;
    // 创建按钮
    private HButton hbHelp, hbPlay, hbExit, hbResume, hbReplay, hbBack, hbMenu;
 
    public MySurfaceView(Context context) {
        super(context);
        this.setKeepScreenOn(true);
        sfh = this.getHolder();
        sfh.addCallback(this);
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStyle(Style.STROKE);
        this.setFocusable(true);
        this.setFocusableInTouchMode(true);
        // --添加一个物理世界--->>
        aabb = new AABB();
        gravity = new Vec2(0, 10);
        aabb.lowerBound.set(-100, -100);
        aabb.upperBound.set(100, 100);
        world = new World(aabb, gravity, true);
        // ---实例化Body图片资源
        bmpH = BitmapFactory.decodeResource(getResources(), R.drawable.h);
        bmpS = BitmapFactory.decodeResource(getResources(), R.drawable.s);
        bmpSh = BitmapFactory.decodeResource(getResources(), R.drawable.sh);
        bmpSs = BitmapFactory.decodeResource(getResources(), R.drawable.ss);
        bmpBall = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
        // 实例菜单、按钮、游戏背景图片资源
        bmpMenu_help = BitmapFactory.decodeResource(getResources(), R.drawable.menu_help);
        bmpMenu_play = BitmapFactory.decodeResource(getResources(), R.drawable.menu_play);
        bmpMenu_exit = BitmapFactory.decodeResource(getResources(), R.drawable.menu_exit);
        bmpMenu_resume = BitmapFactory.decodeResource(getResources(), R.drawable.menu_resume);
        bmpMenu_replay = BitmapFactory.decodeResource(getResources(), R.drawable.menu_replay);
        bmp_menubg = BitmapFactory.decodeResource(getResources(), R.drawable.menu_bg);
        bmp_gamebg = BitmapFactory.decodeResource(getResources(), R.drawable.game_bg);
        bmpMenuBack = BitmapFactory.decodeResource(getResources(), R.drawable.menu_back);
        bmp_smallbg = BitmapFactory.decodeResource(getResources(), R.drawable.smallbg);
        bmpMenu_menu = BitmapFactory.decodeResource(getResources(), R.drawable.menu_menu);
        bmp_helpbg = BitmapFactory.decodeResource(getResources(), R.drawable.helpbg);
        bmpBody_lost = BitmapFactory.decodeResource(getResources(), R.drawable.lostbody);
        bmpBody_win = BitmapFactory.decodeResource(getResources(), R.drawable.winbody);
        bmpWinbg = BitmapFactory.decodeResource(getResources(), R.drawable.gamewin);
        bmpLostbg = BitmapFactory.decodeResource(getResources(), R.drawable.gamelost);
    }
    //SurfaceView创建
    public void surfaceCreated(SurfaceHolder holder) {
        //防止Home按键导致游戏重置
        if (gameState == GAMESTATE_MENU) {
            screenW = this.getWidth();
            screenH = this.getHeight();
            // 实例化按钮
            hbPlay = new HButton(bmpMenu_play, screenW / 2 - bmpMenu_help.getWidth() / 2, 150);
            hbHelp = new HButton(bmpMenu_help, hbPlay.getX(), hbPlay.getY()   50);
            hbExit = new HButton(bmpMenu_exit, hbPlay.getX(), hbHelp.getY()   50);
            hbBack = new HButton(bmpMenuBack, 0, screenH - bmpMenu_help.getHeight());
            hbResume = new HButton(bmpMenu_resume, screenW / 2 - bmpMenu_help.getWidth() / 2, 200);
            hbReplay = new HButton(bmpMenu_replay, hbResume.getX(), hbResume.getY()   50);
            hbMenu = new HButton(bmpMenu_menu, hbResume.getX(), hbReplay.getY()   50);
            // 创建主角小球
            bodyBall = createCircle(bmpBall, bmpH.getHeight(), bmpH.getHeight(), bmpBall.getWidth() / 2, 5);
            //创建胜负Body
            lostBody1 = createCircle(bmpBody_lost, screenW - bmpH.getHeight() - bmpBody_lost.getWidth(), bmpH.getHeight(), bmpBody_lost.getWidth() / 2, 0);
            lostBody2 = createCircle(bmpBody_lost, bmpH.getHeight(), screenH - bmpH.getHeight() - bmpBody_lost.getHeight(), bmpBody_lost.getWidth() / 2, 0);
            winBody = createCircle(bmpBody_win, screenW - bmpH.getHeight() - bmpBody_win.getWidth(), screenH - bmpH.getHeight() - bmpBody_win.getHeight(),
                    bmpBody_win.getWidth() / 2, 0);
            //设置传感器,发生碰撞,但无碰撞效果
            lostBody1.getShapeList().m_isSensor = true;
            lostBody2.getShapeList().m_isSensor = true;
            winBody.getShapeList().m_isSensor = true;
            // 创建边界
            createRect(bmpH, 0, 0, bmpH.getWidth(), bmpH.getHeight(), 0);// 上
            createRect(bmpH, 0, getHeight() - bmpH.getHeight(), bmpH.getWidth(), bmpH.getHeight(), 0);// 下
            createRect(bmpS, 0, 0, bmpS.getWidth(), bmpS.getHeight(), 0);// 左
            createRect(bmpS, getWidth() - bmpS.getWidth(), 0, bmpS.getWidth(), bmpS.getHeight(), 0);// 右
            // -----创建障碍物
            createRect(bmpSh, 0, 90, bmpSh.getWidth(), bmpSh.getHeight(), 0);
            createRect(bmpSh, 110, 170, bmpSh.getWidth(), bmpSh.getHeight(), 0);
            createRect(bmpSs, 110, 170, bmpSs.getWidth(), bmpSs.getHeight(), 0);
            createRect(bmpSs, getWidth() - 102, screenH - bmpSs.getHeight(), bmpSs.getWidth(), bmpSs.getHeight(), 0);
            //绑定监听器
            world.setContactListener(this);
        }
        flag = true;
        th = new Thread(this);
        th.start();
    }
 
    //在物理世界中添加矩形Body
    public Body createRect(Bitmap bmp, float x, float y, float w, float h, float density) {
        PolygonDef pd = new PolygonDef();
        pd.density = density;
        pd.friction = 0.8f;
        pd.restitution = 0.3f;
        pd.setAsBox(w / 2 / RATE, h / 2 / RATE);
        BodyDef bd = new BodyDef();
        bd.position.set((x   w / 2) / RATE, (y   h / 2) / RATE);
        Body body = world.createBody(bd);
        body.m_userData = new MyRect(bmp, x, y);
        body.createShape(pd);
        body.setMassFromShapes();
        return body;
    }
 
    //在物理世界中添加圆形Body
    public Body createCircle(Bitmap bmp, float x, float y, float r, float density) {
        CircleDef cd = new CircleDef();
        cd.density = density;
        cd.friction = 0.8f;
        cd.restitution = 0.3f;
        cd.radius = r / RATE;
        BodyDef bd = new BodyDef();
        bd.position.set((x   r) / RATE, (y   r) / RATE);
        Body body = world.createBody(bd);
        body.m_userData = new MyCircle(bmp, x, y, r);
        body.createShape(cd);
        body.setMassFromShapes();
        //放置小球进入休眠,导致改变重力方向,小球无法移动
        body.allowSleeping(false);
        return body;
    }
 
    public void myDraw() {
        try {
            canvas = sfh.lockCanvas();
            canvas.drawColor(Color.BLACK);
            switch (gameState) {
            case GAMESTATE_MENU:
                //绘制主菜单背景
                canvas.drawBitmap(bmp_menubg, 0, 0, paint);
                //绘制Play按钮
                hbPlay.draw(canvas, paint);
                //绘制Help按钮
                hbHelp.draw(canvas, paint);
                //绘制Exit按钮
                hbExit.draw(canvas, paint);
                break;
            case GAMESTATE_HELP:
                //绘制帮助界面背景
                canvas.drawBitmap(bmp_helpbg, 0, 0, paint);
                //绘制Back按钮
                hbBack.draw(canvas, paint);
                break;
            case GAMESTATE_GAMEING:
                //绘制游戏背景
                canvas.drawBitmap(bmp_gamebg, 0, 0, paint);
                //遍历物理世界中所有存在的Body;
                Body body = world.getBodyList();
                for (int i = 1; i < world.getBodyCount(); i  ) {
                    if ((body.m_userData) instanceof MyRect) {
                        MyRect rect = (MyRect) (body.m_userData);
                        rect.drawMyRect(canvas, paint);
                    } else if ((body.m_userData) instanceof MyCircle) {
                        MyCircle mcc = (MyCircle) (body.m_userData);
                        mcc.drawArc(canvas, paint);
                    }
                    body = body.m_next;
                }
                //当游戏暂停或失败或成功时
                if (gameIsPause || gameIsLost || gameIsWin) {
                    // 当游戏暂停或失败或成功时画一个半透明黑色矩形,突出界面
                    Paint paintB = new Paint();
                    paintB.setAlpha(0x77);
                    canvas.drawRect(0, 0, screenW, screenH, paintB);
                }
                // 游戏暂停
                if (gameIsPause) {
                    //绘制暂停背景
                    canvas.drawBitmap(bmp_smallbg, screenW / 2 - bmp_smallbg.getWidth() / 2, screenH / 2 - bmp_smallbg.getHeight() / 2, paint);
                    //绘制Resume按钮
                    hbResume.draw(canvas, paint);
                    //绘制Replay按钮
                    hbReplay.draw(canvas, paint);
                    //绘制Menu按钮
                    hbMenu.draw(canvas, paint);
                } else
                //游戏失败
                if (gameIsLost) {
                    //绘制游戏背景
                    canvas.drawBitmap(bmpLostbg, screenW / 2 - bmpLostbg.getWidth() / 2, screenH / 2 - bmpLostbg.getHeight() / 2, paint);
                    //绘制Replay按钮
                    hbReplay.draw(canvas, paint);
                    //绘制Menu按钮
                    hbMenu.draw(canvas, paint);
                } else
                //游戏胜利
                if (gameIsWin) {
                    //绘制失败背景
                    canvas.drawBitmap(bmpWinbg, screenW / 2 - bmpWinbg.getWidth() / 2, screenH / 2 - bmpWinbg.getHeight() / 2, paint);
                    //绘制Replay按钮
                    hbReplay.draw(canvas, paint);
                    //绘制Menu按钮
                    hbMenu.draw(canvas, paint);
                }
                break;
            }
        } catch (Exception e) {
            Log.e("Himi", "myDraw is Error!");
        } finally {
            if (canvas != null)
                sfh.unlockCanvasAndPost(canvas);
        }
    }
 
    /**
     * 触屏按键事件处理
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (gameState) {
        case GAMESTATE_MENU:
            //判断Play按钮是否被点击
            if (hbPlay.isPressed(event)) {
                //Play按钮被点击开始游戏
                gameState = GAMESTATE_GAMEING;
                //判断Help按钮是否被点击
            } else if (hbHelp.isPressed(event)) {
                //Play按钮被点击进入游戏游戏帮助界面
                gameState = GAMESTATE_HELP;
                //判断Exit按钮是否被点击
            } else if (hbExit.isPressed(event)) {
                //Exit按钮被点击调用退出函数
                MainActivity.main.exit();
            }
            break;
        case GAMESTATE_HELP:
            //判断Back按钮是否被点击
            if (hbBack.isPressed(event)) {
                //Back按钮被点击进入主菜单界面
                gameState = GAMESTATE_MENU;
            }
            break;
        case GAMESTATE_GAMEING:
            // 游戏暂停(因为游戏失败和游戏胜利中按钮处理事件一样,所以就不需要重写)
            if (gameIsPause || gameIsLost || gameIsWin) {
                if (hbResume.isPressed(event)) {
                    gameIsPause = false;
                } else if (hbReplay.isPressed(event)) {
                    //因为在重置前小球可能拥有力,所以重置游戏要先使用putToSleep()方法
                    //让其Body进入睡眠,并让Body停止模拟,速度置为0
                    bodyBall.putToSleep();
                    // 然后对小球的坐标进行重置
                    bodyBall.setXForm(new Vec2((bmpH.getHeight()   bmpBall.getWidth() / 2   2) / RATE, (bmpH.getHeight()   bmpBall.getWidth() / 2   2) / RATE),
                            0);
                    //并且设置默认重力方向为向下
                    world.setGravity(new Vec2(0, 10));
                    //唤醒小球
                    bodyBall.wakeUp();
                    //游戏暂停、胜利、失败条件还原默认false
                    gameIsPause = false;
                    gameIsLost = false;
                    gameIsWin = false;
                } else if (hbMenu.isPressed(event)) {
                    //因为在重置前小球可能拥有力,所以重置游戏要先使用putToSleep()方法
                    //让其Body进入睡眠,并让Body停止模拟,速度置为0
                    bodyBall.putToSleep();
                    // 然后对小球的坐标进行重置
                    bodyBall.setXForm(new Vec2((bmpH.getHeight()   bmpBall.getWidth() / 2   2) / RATE, (bmpH.getHeight()   bmpBall.getWidth() / 2   2) / RATE),
                            0);
                    //并且设置默认重力方向为向下
                    world.setGravity(new Vec2(0, 10));
                    //唤醒小球
                    bodyBall.wakeUp();
                    //重置游戏状态为主菜单
                    gameState = GAMESTATE_MENU;
                    //游戏暂停、胜利、失败条件还原默认false
                    gameIsPause = false;
                    gameIsLost = false;
                    gameIsWin = false;
                }
            }
            break;
        }
        return true;
    }
 
    /**
     * 实体键盘按键处理
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // 当前游戏状态不处于正在游戏中时,屏蔽“返回”实体按键,避免程序进入后台;
        if (keyCode == KeyEvent.KEYCODE_BACK && gameState != GAMESTATE_GAMEING) {
            return true;
        }
        switch (gameState) {
        case GAMESTATE_MENU:
            break;
        case GAMESTATE_HELP:
            break;
        case GAMESTATE_GAMEING:
            // 游戏没有暂停、失败、胜利
            if (!gameIsPause && !gameIsLost && !gameIsWin) {
                //如果方向键左键被按下
                if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT)
                    //设置物理世界的重力方向向左 
                    world.setGravity(new Vec2(-10, 2));
                //如果方向键右键被按下
                else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)
                    //设置物理世界的重力方向向右
                    world.setGravity(new Vec2(10, 2));
                //如果方向键上键被按下
                else if (keyCode == KeyEvent.KEYCODE_DPAD_UP)
                    //设置物理世界的重力方向向上
                    world.setGravity(new Vec2(0, -10));
                //如果方向键下键被按下
                else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
                    //设置物理世界的重力方向向下
                    world.setGravity(new Vec2(0, 10));
                //如果返回键被按下
                else if (keyCode == KeyEvent.KEYCODE_BACK) {
                    //进入游戏暂停界面
                    gameIsPause = true;
                }
            }
            //屏蔽“返回”实体按键,避免程序进入后台;
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
 
    //游戏逻辑函数
    public void Logic() {
        switch (gameState) {
        case GAMESTATE_MENU:
            break;
        case GAMESTATE_HELP:
            break;
        case GAMESTATE_GAMEING:
            // 游戏没有暂停
            if (!gameIsPause && !gameIsLost && !gameIsWin) {
                // --开始模拟物理世界--->>
                world.step(timeStep, iterations);
                Body body = world.getBodyList();
                for (int i = 1; i < world.getBodyCount(); i  ) {
                    if ((body.m_userData) instanceof MyRect) {
                        MyRect rect = (MyRect) (body.m_userData);
                        rect.setX(body.getPosition().x * RATE - rect.getW() / 2);
                        rect.setY(body.getPosition().y * RATE - rect.getH() / 2);
                    } else if ((body.m_userData) instanceof MyCircle) {
                        MyCircle mcc = (MyCircle) (body.m_userData);
                        mcc.setX(body.getPosition().x * RATE - mcc.getR());
                        mcc.setY(body.getPosition().y * RATE - mcc.getR());
                        mcc.setAngle((float) (body.getAngle() * 180 / Math.PI));
                    }
                    body = body.m_next;
                }
            }
            break;
        }
    }
 
    public void run() {
        while (flag) {
            myDraw();
            Logic();
            try {
                Thread.sleep((long) timeStep * 1000);
            } catch (Exception ex) {
                Log.e("Himi", "Thread is Error!");
            }
        }
    }
 
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }
 
    public void surfaceDestroyed(SurfaceHolder holder) {
        flag = false;
    }
 
    @Override
    public void add(ContactPoint point) {
        //当前游戏状态为进行游戏时
        if (gameState == GAMESTATE_GAMEING) {
            //游戏没有进入暂停、失败、胜利界面
            if (!gameIsPause && !gameIsLost && !gameIsWin) {
                //判定主角小球是否与失败小球1发生碰撞
                if (point.shape1.getBody() == bodyBall && point.shape2.getBody() == lostBody2) {
                    //游戏失败
                    gameIsLost = true;
                    //判定主角小球是否与失败小球2发生碰撞
                } else if (point.shape1.getBody() == bodyBall && point.shape2.getBody() == lostBody1) {
                    //游戏失败
                    gameIsLost = true;
                    //判定主角小球是否与胜利小球发生碰撞
                } else if (point.shape1.getBody() == bodyBall && point.shape2.getBody() == winBody) {
                    //游戏胜利
                    gameIsWin = true;
                }
            }
        }
    }
 
    @Override
    public void persist(ContactPoint point) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void remove(ContactPoint point) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void result(ContactResult point) {
        // TODO Auto-generated method stub
 
    }
 
}

 

以上就是本次关于本资源的介绍和部分内容,我们还整理了以往更新的其它相关资源内容,可以在下方直接下载,关于相关的资源我们在下方做了关联展示,需要的朋友们也可以参考下。

android游戏源码相关资源

  • 深入解析Android 5.0系统

    深入解析Android 5.0系统

    《深入解析Android 5.0系统》 详细剖析了最新Android 5.0 系统主要框架的原理和具体实现。本书共24章,覆盖了Android 5.0 系统中、下层重要的模块,对于每个模块都详细介绍了它们的架构、原理及代

    大小:140 MBAndroid电子书

  • Android程序设计

    Android程序设计

    本书适合不同背景的 Android编程人员。如果你一直在用Objective-C为iPhone或Mac OS编写应用,你会发现本书中Android 工具和Java语言特性等与Android编程相关的介绍能够帮助你理解Android移动应用开发

    大小:17.7 MBAndroid开发电子书

  • AndroidStudio从入门到精通

    Android Studio从入门到精通 ,非常适合初学者看,虽然Android studio 不是最新的版本,但是里面的操作版面基本差不多,建议初学者下来看看。 目录 第 一 章 Android Studio 简介及其环境搭 第 二 章 Android Studio 基本概念 第 三 章 Android Studio 编程语言基础 第 四 章 Android Studio 界面布局 第 五 章 Android Studio 视图工具箱 第 六 章 多线程的实现 第 七 章管理 Activity 生命周期

    大小:5.3 MBAndroidStudio

  • Android开发实战:从学习到产品

    Android开发实战:从学习到产品

    大小:90 MBAndroid电子书

  • Android应用案例开发大全

    Android应用案例开发大全

    Android应用案例开发大全 出版时间:2018 本书以讲解Android 手机综合应用程序开发为主题,通过11 个典型范例全面且深入地讲解了单机应用、网络应用、商业案例、游戏案例等多个开发技术。 全书共分12 章,详细介绍了3D 动态壁纸—百纳水族馆,LBS 类应用—掌上杭州,营销管理系 统—手机汽车4S 店,LBS 交通软件—百纳公交小助手,校园服务类应用—社团宝,校园辅助软件— 手机新生小助手,生活辅助类应用—美食天下,音乐休闲软件—百纳网络音乐播放

    大小:26 MBAndroid电子书

  • Android程序设计经典教程

    Android程序设计经典教程

    Android程序设计经典教程 从初学者的角度出发,通过通俗易懂的语言、丰富多彩的实例介绍了Android程序开发的各方面技术。本书在介绍Android技术的同时,提供一些经典案例,通过经典案例让读

    大小:82.7 MBAndroid电子书

  • java,android面试宝典

    大小:280 KB面试

下载地址

用户留言

12小时7分钟前回答

深入剖析Android中init进程实现的C语言源码

概述 init是一个进程,确切的说,它是Linux系统中用户空间的第一个进程。由于Android是基于Linux内核的,所以init也是Android系统中用户空间的第一个进程。init的进程号是1。作为天字第一号进程,init有很多重要的工作: init提供property service(属性服务)来管理Android系统的属性。 init负责创建系统中的关键进程,包括zygote。 以往的文章一上来就介绍init的源码,但是我这里先从这两个……

6小时56分钟前回答

详细分析Android中实现Zygote的源码

概述 在Android系统中,所有的应用程序进程,以及用来运行系统关键服务的System进程都是由zygote进程负责创建的。因此,我们将它称为进程孵化器。zygote进程是通过复制自身的方式来创建System进程和应用程序进程的。由于zygote进程在启动时会在内部创建一个虚拟机实例,因此,通过复制zygote进程而得到的System进程和应用程序进程可以快速地在内部获得一个虚拟机实例拷贝。 zygot……

1小时55分钟前回答

Android基于TCP和URL协议的网络编程示例【附demo源码下载】

本文实例讲述了Android基于TCP和URL协议的网络编程。分享给大家供大家参考,具体如下: 手机本身是作为手机终端使用的,因此它的计算能力,存储能力都是有限的。它的主要优势是携带方便,可以随时打开,而且手机通常总是处于联网状态。因此网络支持对于手机应用非常重要。 Android完全支持JDK本身的TCP,UDP网络通信API,也可以使用ServerSocket,Socket来建立基于TCP/IP协议的网络通……