-1

Hy everyone, I am newbie and I have some how know. please help me.

  1. start two processes in One Application. I make a AppLock
  2. create AppLock application. if user one process stop/kill then second process start it. please tell me it is valid or not if not valid then tell me correct way to start application after force stop/kill. thanks Edit

3) can I restart application after stop with IntentService. I read Intent service cant run on Main Thread

3
  • I am fresher please give me right way not down voted. SO is for learning purpose Commented Aug 10, 2015 at 7:38
  • 1
    SO is about helping those who are trying to learn, it's not about teaching those who don't want to study on their own. You haven't shown us anything that demonstrated your efforts on this purpose, nobody here will write the code for you - but we will gladly help you with fixing the existing one Commented Aug 10, 2015 at 7:58
  • I attempted with broadcast Receiver in the method of service (onDestroy) Commented Aug 10, 2015 at 9:29

1 Answer 1

2

See this: https://stackoverflow.com/a/6567878/850347

You can make more than one process by using setting below.

 android:process=":remote"

Edit1

Alright.
Step1: Make app that has one local process, one global process.

AndroidManifest.xml Note that Setting capital letter for process name makes local process, and small letter process name makes global process.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kou.processtest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="18" />

    <application>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LocalProcessActivity"
            android:process=":Local1" />
        <activity
            android:name=".GlobalProcessActivity"
            android:process=".global1" />
    </application>

</manifest>

MainActivity.java

package com.kou.processtest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ((Button) findViewById(R.id.btn1)).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, GlobalProcessActivity.class);
                startActivity(intent);
            }
        });

    }

}

GlobalProcessActivity.java

package com.kou.processtest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class GlobalProcessActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_global_process);

        ((Button) findViewById(R.id.btn1)).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(GlobalProcessActivity.this, LocalProcessActivity.class);
                startActivity(intent);
            }
        });

    }
}

LocalProcessActivity.java

package com.kou.processtest;

import android.app.Activity;
import android.os.Bundle;

public class LocalProcessActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_local_process);
    }
}

activity_main.xml

<RelativeLayout xmlns: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"
    tools:context="${packageName}.${activityClass}" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="run global process" />

</RelativeLayout>

activity_global_process.xml

<RelativeLayout xmlns: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"
    tools:context="${packageName}.${activityClass}" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="run local process" />

</RelativeLayout>

activity_local_process.xml

<RelativeLayout xmlns: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"
    tools:context="${packageName}.${activityClass}" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="nothing" />

</RelativeLayout>


Step2: Run app. press button to run global process activity, and local process activity.

Step3: Check process by adb shell, ps. You can see the three processes.

C:\>adb shell ps
u0_a678   19654 2019  553956 33848 ffffffff 00000000 S com.kou.processtest
u0_a678   19680 2019  553952 34008 ffffffff 00000000 S .global1
u0_a678   19701 2019  558020 33588 ffffffff 00000000 S com.kou.processtest:Local1

Step4: Kill application on Setting menu. Setting - App - App info - Force stop

Step5: Run ps again.

Result: all process was killed.
com.kou.processtest and .global1 and com.kou.processtest:Local1 was all killed.

Sign up to request clarification or add additional context in comments.

6 Comments

if application stop then all processes stop or not @Stanley Kou??
@bobjeffer This will help you: stackoverflow.com/a/27963774/850347 First, don't let application crash. And your remote process will not crash if application crashs, but it depends on it's condition. And, because your remote process will communicate with your application, your app will not works properly. You can see details: developer.android.com/guide/components/… developer.android.com/guide/topics/processes/…
sir if click on Settings -> Apps>Force Stop then both processes kill?
@bobjeffer Yes, and I wrote details. But, force stop is far different case what I thought. If you want "Always Resurrect app", See this: stackoverflow.com/questions/2681499/…
Thanks a lot sir you solve my problem...I wish give you points but :(
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.