posted by 네코냥이 2015. 4. 1. 15:37


How to exit an android app using code?




You can call System.exit(); to get out of all the acivities.

    submit=(Button)findViewById(R.id.submit);

            submit.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
android.os.Process.killProcess(android.os.Process.myPid());
                    System.exit(1);

                }
            });
shareimprove this answer








'JAVA > Android' 카테고리의 다른 글

[스크랩] Activity Flag  (0) 2015.04.13
다른 어플 실행  (0) 2015.04.01
안드로이드 Process Name 및 Id  (666) 2015.03.31
안드로이드 뷰 동적으로 마진주기  (0) 2015.03.15
브로드 캐스트 리시버 기본 사용예제.  (0) 2015.01.13
posted by 네코냥이 2015. 3. 31. 15:10



-----


No need to use grep. ps in Android can filter by COMM value (last 15 characters of the package name in case of java app)

Let's say we want to check if com.android.phone is running:

adb shell ps m.android.phone
USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
radio     1389  277   515960 33964 ffffffff 4024c270 S com.android.phone


-----


for (RunningAppProcessInfo runningProInfo : runningProcInfo) {

    int pid = runningProInfo.pid;

    Log.e(TAG+"-pid", ""+pid);

}


-----


http://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo.html


RunningAppProcessInfo 
public intimportanceThe relative importance level that the system places on this process.
public intimportanceReasonCodeThe reason for importance, if any.
public ComponentNameimportanceReasonComponentFor the specified values of importanceReasonCode, this is the name of the component that is being used in this process.
public intimportanceReasonPidFor the specified values of importanceReasonCode, this is the process ID of the other process that is a client of this process.
public intlastTrimLevelLast memory trim level reported to the process: corresponds to the values supplied toComponentCallbacks2.onTrimMemory(int).
public intlruAn additional ordering within a particular importance category, providing finer-grained information about the relative utility of processes within a category.
public intpidThe pid of this process; 0 if none
public String[]pkgListAll packages that have been loaded into the process.
public StringprocessNameThe name of the process that this object is associated with
public intuidThe user id of this process.



---------



Is process name same as package name in android?




By default android takes the package name as the process name. But if you define process property in application tag in manifest file android:process="com.example.newprocessname" then the application will run with this name "com.example.newprocessname".

As for your questions,

Hope this answers your question!

shareimprove this answer



'JAVA > Android' 카테고리의 다른 글

다른 어플 실행  (0) 2015.04.01
어플 종료  (0) 2015.04.01
안드로이드 뷰 동적으로 마진주기  (0) 2015.03.15
브로드 캐스트 리시버 기본 사용예제.  (0) 2015.01.13
안드로이드 AIDL  (0) 2015.01.13
posted by 네코냥이 2015. 3. 15. 09:34




How to set margin dynamically in Android_ - Stack Overflow.pdf













'JAVA > Android' 카테고리의 다른 글

어플 종료  (0) 2015.04.01
안드로이드 Process Name 및 Id  (666) 2015.03.31
브로드 캐스트 리시버 기본 사용예제.  (0) 2015.01.13
안드로이드 AIDL  (0) 2015.01.13
[Android] 전화걸기  (0) 2014.11.28
posted by 네코냥이 2015. 1. 13. 17:36


#24 Broadcast Receiver로 문자(SMS) 수신해보자 __ 미르의 IT 정복기.pdf


'JAVA > Android' 카테고리의 다른 글

안드로이드 Process Name 및 Id  (666) 2015.03.31
안드로이드 뷰 동적으로 마진주기  (0) 2015.03.15
안드로이드 AIDL  (0) 2015.01.13
[Android] 전화걸기  (0) 2014.11.28
[안드로이드] 키보드 숨기기.  (0) 2014.11.27
posted by 네코냥이 2015. 1. 13. 13:47



Thinker __ Android AIDL(Android Interface description language).pdf



[android_안드로이드] aidl 을 이용하여 service 에 bind 하기.pdf



Holic Spirit __ Tistory Edition __ 안드로이드 리모트 서비스 만들기 #1.pdf


posted by 네코냥이 2014. 11. 28. 11:34


/****************************************************************/


public class TelCall extends Activity {

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.telcall);

    }

 

    public void mOnClick(View v) {

        Uri number;

        Intent intent;

        number = Uri.parse("tel:000-000-0000"); // 번호 수정해주시면 됩니다.

        intent = new Intent(Intent.ACTION_DIAL, number); // ACTION_CALL : 바로걸기

        startActivity(intent);

        break;

    }

}


/****************************************************************/


posted by 네코냥이 2014. 11. 27. 15:57

private void particle_HideKeyboard() {

if(getCurrentFocus()!=null) {

        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

    }

}

'JAVA > Android' 카테고리의 다른 글

안드로이드 AIDL  (0) 2015.01.13
[Android] 전화걸기  (0) 2014.11.28
Adding View to RemoteViews in Android  (0) 2014.11.18
Adding the AppWidgetProviderInfo Metadata  (0) 2014.11.18
하나에 App에 다수의 App Widget  (0) 2014.11.18
posted by 네코냥이 2014. 11. 18. 17:51
RemoteViews update = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    for (int i = 0; i < 3; i++) {
        RemoteViews textView = new RemoteViews(context.getPackageName(), R.layout.test);
        textView.setTextViewText(R.id.textView1, "TextView number " + String.valueOf(i));
        update.addView(R.id.ll_widget, textView);
    }

    appWidgetManager.updateAppWidget(appWidgetIds, update);


posted by 네코냥이 2014. 11. 18. 16:13

3. Adding the AppWidgetProviderInfo Metadata

AppWidgetProviderInfo 는 xml 파일로 정의하며, App Widget 을 작성하기 위해서 반드시 필요한 파일이다. 이 XML 파일에는 initial layout resource, App Widget 의 upate 주기, 그리고 옵션으로 처음 생성 시점에 실행되는 configuration Activity 정보를 설정한다. XML 파일에 <appwidget-provider> element 로 정의하며, XML 파일은 /res/xml 디렉토리에 위치한다.

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"

    android:minWidth="294dp"

    android:minHeight="72dp"

    android:updatePeriodMillis="86400000"

    android:previewImage="@drawable/preview" <!-- android 3.0 이후에 추가 -->

    android:initialLayout="@layout/example_appwidget"

    android:configure="com.example.android.ExampleAppWidgetConfigure"

    android:resizeMode="horizontal|vertical"<!-- android 3.1 이후에 추가 -->

</appwidget-provider>

다음은 각 attribute 에 대한 설명이다.

3.1 minWidth 와 minHeight

AppWidget layout 의 최소 폭과 높이의 값을 설정한다.

Home Screen 에 보여질 Widget 에 대한 높이와 폭을 지정하는 것이다. Home Screen 은 아이콘 크기의 Cell 형태로 이루어지져 있다. 따라서 Widget 의 폭과 높이를 지정할 때, HomeScreen 에 놓여질 Cell 의 크기를 기준으로 계산을 해야한다. 기본적인 Cell 의 크기는 74 dp 이며, 그 값을 계산하는 방식은 아래와 같다.

(number of cell * 74)  - 2

주의 : Home Screen 에서 Widget 이 가질 수 있는 최대의 Cell 의 갯수는 4 x 4 이다, 이보다 크게 Widget 의 크기를 디자인해서는 안된다.

3.2 updatePeriodMillis

AppWidget Framework 가 AppWidgeProvider.onUpdate() 메소드를 얼마나 자주 호출해야 하는지를 정의한다. 하지만 실제로 onUpdate() 가 정확한 시간에 호출되는지는 보증할 수 없다. 가능한한 제 시간에 호출되는 것으로 가정해야 하며, 어떨 때는 Battery 문제로 인하여  한시간에 한번도 호출되지 않을 수도 있다. 주로 사용자가 15분 주기 또는 1시간 주기등으로 설정한다.

주의 : updatePeriodMillis 를 설정해 놓으면 Device 가 sleep mode(주로 화면이 꺼진 상태) 로 되어있을 지라도 update 를 수행하기 위해서 Device 를 깨워서 동작을 한다. 이러한 작업이 1시간 주기로 동작하면, Battery 문제가 없지만, 자주 호출이 되면 Battery 를 많이 소모하게 된다. 따라서 Device 가 꺠어있는 상태에서만 동작하도록 하려면 updatePeriodMillis 의 값은 “0” 으로 설정하고, AlarmManager 를 사용하여 주기적으로 동작하도록 설정해야 한다. 이때 Alarm 의 Type 은 ELASPED_REALTIME 또는 RTC  로 설정하면 된다.

3.3 initialLayout

AppWidget layout 을 정의하기 위한 layout resource 를 지정한다.

3.4 configure

사용자가 App Widget 을 추가할 때 실행할 Activity 를 지정한다. 이 Activity 는 App Widget 의 환경설정을 하는데 주로 사용한다.

3.5 previewImage

App Widget 을 추가하기 위해서 Menu 를 선택하고 App Widget 목록에서 해당 Widget 에 대한 미리보기 이미지를 지정한다. 이 항목이 지정되지 않았을 경우에는 디폴트 Icon 으로 나타난다. 이 속성은 Android 3.0 부터 지원한다.

3.6 autoAdvanceViewId

해당 Widget host 에 의해서 auto-advanced 되어야 하는 App Widget subview 의 view ID 를 기술한다. 이 속성은 Android 3.0 부터 지원한다.

3.7 resizeMode

Home Screen 에서 Widget 의 폭과 높이에 대해서 Resize 할 것인지를 정의한다. 값은 “vertical”, “horizontal”, “none” 으로 설정한다. 이 속성은 Android 3.1 부터 지원한다.

posted by 네코냥이 2014. 11. 18. 15:58

리시버를 2개 선언하되,

해당 프로바이더는 다른 클래스를 가르키고 있다.

공통된 부분이 있다면 따로 모듈로 빼는 수밖에 없다.


You need a receiver definition for each type in your manifest file like:

    <receiver android:name=".MyWidget" android:label="@string/medium_widget_name">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/medium_widget_provider" />
    </receiver>

    <receiver android:name=".MyWidget" android:label="@string/large_widget_name">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/large_widget_provider" />
    </receiver>

This would allow you to have the same AppWidgetProvider class be used for multiple widgets, with different widget names and different sizes defined in the <appwidget-provider> XML.

Now if you need more differences in your widgets than what is in the <appwidget-provider> XML I would create a base widget class that implements all the common behavoir between the different types:

public abstract class MyBaseWidget extends AppWidgetProvider

And then each of your concrete implementations could extend MyBaseWidget. Then in your manifest file you would have a receiver definition for each of your concrete implementations like:

    <receiver android:name=".MyMediumWidget" android:label="@string/medium_widget_name">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/medium_widget_provider" />
    </receiver>

    <receiver android:name=".MyLargeWidget" android:label="@string/large_widget_name">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/large_widget_provider" />
    </receiver>
share|edit|flag