-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

bob jeffer
  • 25
  • 3
  • I am fresher please give me right way not down voted. SO is for learning purpose – bob jeffer Aug 10 '15 at 07: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 – Chaosit Aug 10 '15 at 07:58
  • I attempted with broadcast Receiver in the method of service (onDestroy) – bob jeffer Aug 10 '15 at 09:29

1 Answers1

1

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.

Community
  • 1
  • 1
Stanley Ko
  • 3,383
  • 3
  • 34
  • 60
  • if application stop then all processes stop or not @Stanley Kou?? – bob jeffer Aug 10 '15 at 12:28
  • @bobjeffer This will help you: http://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: http://developer.android.com/guide/components/processes-and-threads.html http://developer.android.com/guide/topics/processes/process-lifecycle.html – Stanley Ko Aug 11 '15 at 01:33
  • sir if click on Settings -> Apps>Force Stop then both processes kill? – bob jeffer Aug 11 '15 at 04:50
  • @bobjeffer Yes, and I wrote details. But, force stop is far different case what I thought. If you want "Always Resurrect app", See this: http://stackoverflow.com/questions/2681499/android-how-to-auto-restart-application-after-its-been-force-closed – Stanley Ko Aug 11 '15 at 08:23
  • Thanks a lot sir you solve my problem...I wish give you points but :( – bob jeffer Aug 11 '15 at 14:46
  • That's alright. :) You can accept my answer, may be. http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Stanley Ko Aug 12 '15 at 04:03