麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

私有進程和全局進程的區別

2019-11-09 14:16:20
字體:
來源:轉載
供稿:網友

私有進程

android:PRocess=":remote",以冒號開頭,冒號后面的字符串原則上是可以隨意指定的。如果我們的包名為“com.example.processtest”,則實際的進程名

為“com.example.processtest:remote”。這種設置形式表示該進程為當前應用的私有進程,其他應用的組件不可以和它跑在同一個進程中。

全局進程

進程名稱不以“:”開頭的進程都可以叫全局進程,如android:process="com.example.processtest.remote",以小寫字母開頭,表示運行在一個以這個名字命名的全局進程中,其他

應用通過設置相同的ShareUID可以和它跑在同一個進程。

Demo

com.aji.processdemo包名

project.properties文件

target=android-19

===========================================================

AndroidManifest.xml

<?xmlversion="1.0"encoding="utf-8"?>

<manifestxmlns:android="http://schemas.android.com/apk/res/android"

    package="com.aji.processdemo"

    android:versionCode="1"

    android:versionName="1.0">

 

   <uses-sdk

        android:minSdkVersion="14"

        android:targetSdkVersion="21"/>

 

   <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/APPTheme"

        android:name="com.aji.processdemo.MyApp">

        <activity

           android:name=".MainActivity"

           android:label="@string/app_name">

            <intent-filter>

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

 

                <categoryandroid:name="android.intent.category.LAUNCHER"/>

            </intent-filter>

        </activity>

 

        <!-- 以:開頭的名字,則表示這是一個應用程序的私有進程,私有進程的進程名稱是會在冒號前自動加上包名 -->

        <service

           android:name="com.aji.processdemo.MyService01"

           android:process=":abc">

        </service>

       

        <!-- 進程名稱不以“:”開頭的進程都可以叫全局進程,其他應用通過設置相同的ShareUID可以和它跑在同一個進程 -->

        <service

           android:name="com.aji.processdemo.MyService02"

           android:process="com.aji.test">

        </service>

   </application>

 

</manifest>

===========================================================

activity_main.xml

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    tools:context="com.aji.processdemo.MainActivity">

 

   <Button

        android:id="@+id/btn_01"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="啟動私有進程"/>

 

   <Button

        android:id="@+id/btn_02"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="啟動全局進程"/>

 

</LinearLayout>

===========================================================

MainActivity

package com.aji.processdemo;

 

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

 

public class MainActivity extends Activityimplements OnClickListener {

 

       @Override

       protectedvoid onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              setContentView(R.layout.activity_main);

              findViewById(R.id.btn_01).setOnClickListener(this);

              findViewById(R.id.btn_02).setOnClickListener(this);

       }

 

       @Override

       publicvoid onClick(View v) {

              switch(v.getId()) {

              caseR.id.btn_01:

                     Intentit1 = new Intent(MainActivity.this, MyService01.class);

                     startService(it1);

                     break;

              caseR.id.btn_02:

                     Intentit2 = new Intent(MainActivity.this, MyService02.class);

                     startService(it2);

                     break;

 

              default:

                     break;

              }

       }

}

===========================================================

MyApp.java

package com.aji.processdemo;

 

import java.util.List;

 

import android.app.ActivityManager;

importandroid.app.ActivityManager.RunningAppProcessInfo;

import android.app.Application;

import android.content.Context;

import android.util.Log;

 

public class MyApp extends Application {

 

       @Override

       publicvoid onCreate() {

              super.onCreate();

              //獲取進程Id

              intpid = android.os.Process.myPid();

              //根據進程id獲取進程名稱

              //主進程的名稱就是應用包名,私有進程的名稱會在冒號前面加上包名,全局進程名稱就是android:process設置的內容

              StringpName = getProcessName(this, pid);

              Log.e("m_tag","MyApp onCreate pid:" + pid + " pName:" + pName);

       }

 

       /**

        * 根據進程id獲取進程名稱

        *

        * @param cxt

        * @param pid

        * @return

        */

       publicString getProcessName(Context cxt, int pid) {

              ActivityManageram = (ActivityManager) cxt

                            .getSystemService(Context.ACTIVITY_SERVICE);

              List<RunningAppProcessInfo>runningApps = am.getRunningAppProcesses();

              if(runningApps == null) {

                     returnnull;

              }

              for(RunningAppProcessInfo procInfo : runningApps) {

                     if(procInfo.pid == pid) {

                            returnprocInfo.processName;

                     }

              }

              returnnull;

       }

}

===========================================================

MyService01 私有進程

package com.aji.processdemo;

 

import android.app.Service;

import android.content.Intent;

import android.os.IBinder;

import android.util.Log;

 

public class MyService01 extends Service {

       @Override

       publicIBinder onBind(Intent intent) {

              returnnull;

       }

      

       @Override

       publicint onStartCommand(Intent intent, int flags, int startId) {

              //TODO Auto-generated method stub

              Log.e("m_tag","MyService01==onStartCommand===>"+intent.toString());

              returnSTART_STICKY;

       }

}

===========================================================

MyService02 全局進程

package com.aji.processdemo;

 

import android.app.Service;

import android.content.Intent;

import android.os.IBinder;

import android.util.Log;

 

public class MyService02 extends Service {

       @Override

       publicIBinder onBind(Intent intent) {

              returnnull;

       }

 

       @Override

       publicint onStartCommand(Intent intent, int flags, int startId) {

              Log.e("m_tag","MyService02====onStartCommand===>"+intent.toString());

              returnSTART_STICKY;

       }

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 美国av免费看 | 国产做爰全免费的视频黑人 | 精品在线视频观看 | 欧美顶级毛片在线播放小说 | 成人午夜在线观看视频 | 一区二区三区黄色 | 黄色99视频 | 午夜视频大全 | 福利在线小视频 | 久久国产亚洲精品 | 黄色av片在线观看 | 欧美三级日本三级少妇99 | 久久亚洲精品久久国产一区二区 | 精品国产一区二区三区四 | 国产精品久久久久一区二区 | 免费国产在线视频 | 中文字幕在线播放不卡 | 久久精品国产99国产精品亚洲 | 99精品国产成人一区二区 | 狠狠干天天 | 久草视频国产在线 | 亚洲无av| 国产一区精品在线观看 | 国产精品视频一区二区三区四区国 | 久久99国产精品久久99果冻传媒 | 91嫩草丨国产丨精品入口 | 精品亚洲国产视频 | 丰满年轻岳中文字幕一区二区 | 九九视频精品在线观看 | 国产女厕一区二区三区在线视 | 羞羞的视频在线 | 日本成人一二三区 | 国产精品视频在线观看免费 | 国产精品久久久久国产精品三级 | 国产99久久精品一区二区300 | 久久精品一二三区白丝高潮 | 久久久国产电影 | 国产精品久久久久久久久久了 | 午夜精品久久久久久中宇 | 精品久久久久久综合日本 | 色999久久久精品人人澡69 |