Dear Omkar,

Here is the code to check if the apk pid..

private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager)
getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
 if (yourclassname.class.getName().equalsIgnoreCase(
service.service.getClassName())) {
return true;
}
}
return false;
}

it returns true if succeeded...





On Tue, Sep 2, 2014 at 4:07 PM, Omkar <omk...@gmail.com> wrote:

> Hi Mukesh, Any suggestions on how to get current pid?
> ActivityManager.getRecentTasks is deprecated by google in android OS L for
> provacy purposes. so can not use any ActivityManager method to get current
> PID/Running task. onTrimMemory seems reliable way to get if app is hidden
> or not, but only have problem descibed above.
>
>
> On Monday, September 1, 2014 5:59:44 PM UTC+10, Mukesh Srivastav wrote:
>
>> why not just check the current pid state of the app rather than doing all
>> those things......
>>
>>
>>
>>
>> On Fri, Aug 29, 2014 at 11:25 AM, Omkar <omk...@gmail.com> wrote:
>>
>>> Hi All,
>>> I am working on a App where functionality is when ever User goes out of
>>> the app and comes back it should ask him login details, so when ever user
>>> kicks himself out of app, by pressing home button or multi-task button or
>>> start other app on my app, then my app should automatically logoff/logout
>>> user and when he comes back ask for credentials.
>>>
>>> To check backgrounded state of app I tried using 
>>> ActivityManager.getRecentTasks(1);
>>> and check if topactivity package is other than my app package and if yes
>>> then I assumed app is backgrounded,
>>> This works good till Kitkat/OS L where google has deprecated
>>> ActivityManager.getRecentTasks method for privacy purpose.
>>>
>>> Second solution we implemented was to use ComponentCallbacks2 and check
>>> onTrimMemory(int level) for level = TRIM_MEMORY_UI_HIDDEN. This worked
>>> in almost all cases, but one. onTrimMemory Component call back is
>>> registered for Application class.
>>>
>>> When call to Activity finish() happens onTrimMemory call back will not
>>> be triggered. Say I have activity A and B, Activity A starts Activity B,
>>> Now I complete some work in Activity B and call finish() on B, From time
>>> when finish() on B is called till Activity A's onStart/onResume will be
>>> called, in this timeframe if user press home buttom/ multitask button and
>>> goes out of the app, onTrimMemory is not called and it is not possible to
>>> know if app was backgrounded, because of this we can not logoff session. So
>>> if user gets out of app in that timeframe and goes back he will get same
>>> session back.
>>>
>>> Second case we detect same behavior is, if we call finish() in activity
>>> B's onPause() and user press home/multitask button or start other app from
>>> notification area then because of this finish() call in onPause, we are not
>>> getting onTrimMemory call back.
>>>
>>> There should be some standard api/call back to check if app is
>>> backgrounded, if not, apis like onTrimMemory should be consistent with
>>> their call backs. Kindly help.
>>>
>>>   --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to android-d...@googlegroups.com
>>>
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to android-developers+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Warm Regards,
>> *Mukesh Kumar*,
>> Android Consultant/Freelancer,
>> India,Hyderabad.
>>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Warm Regards,
*Mukesh Kumar*,
Android Consultant/Freelancer,
India,Hyderabad.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to