Activitiy Behavior

by Shekhar » Fri, 23 Apr 2010 01:21:02 GMT


Sponsored Links
 I have a problem.

I have to design an application in which three activities A ,B,C are
such that if I move across the activities, previous
activities are not killed.A,B,C should be in the application stack so
that their OnCreate
function is not called everytime.Activities should be killed only when
finish() is called explicitly.What is the solution for it?

Also what intent flag I should use to call another activity?

Thanks,
Shekhar

--



Activitiy Behavior

by Mark Murphy » Fri, 23 Apr 2010 01:31:11 GMT


 


If the user goes from A -> B -> C, then presses the BACK button, C will
be destroyed. If the user presses the BACK button again, B will be
destroyed.

If the user goes from A -> B, then takes a phone call and meanders away
from your application for a while, A or B may be destroyed to free up
RAM (though you will be able to use onSaveInstanceState() to retain some
knowledge of your current condition).

None of that is avoidable. All of that is very important for the proper
operation of the users' phones.

The only way to have the functionality of A, B, and C all exist as a
unit is for it all to *be* a unit -- having a *single* activity do all
three things.

On the whole, I think Android works better where A, B, and C can work
independently, and so I really recommend you consider why your design
requires those activities to all be in memory at the same time.


I do not understand this question, sorry.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Training in US: 14-18 June 2010:  http://bignerdranch.com 

--


Sponsored Links


Activitiy Behavior

by Shekhar » Fri, 23 Apr 2010 01:55:48 GMT


 Hi,

1.Thanks for your prompt reply.Why I need to have all the three
activities in the stack because I  want to avoid the time it takes
to create the activity.So that user will not feel smoother screen
transition.to explain in a better way suppose that A and B activity
has a text view that updates the timer that is updated from a common
place.

Only objective is to have a smoother transition.

2.What is the use of "Single Top" activity.If I press back key on a
single top activity.Will it be killed?

Thanks,
Shekhar





>



Activitiy Behavior

by Mark Murphy » Fri, 23 Apr 2010 02:02:06 GMT


 


Then improve the performance of the activities, so they start up faster.

Or, redesign the UI such that the transition time between activities is
not going to be distracting for users.


Yes.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Online Training: 10-14 May 2010:  http://onlc.com 

--



Activitiy Behavior

by Shekhar » Fri, 23 Apr 2010 02:22:05 GMT


 Hi Murphy,

Thanks for your suggestions.

I have a basic querry.suppose all  the three activities are declared
as singletop and suppose from activity A i call
B activity with intent flag as

i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActvity(i)

and from B->C the same intent.Now if i call the activity Aor B from C
with the same intent flag .will the oncreate() function of A,B will be
called again?

If not then it means that the A,B,C are there in the application stack
and their old instance is called again? Am I right?

Thanks,
Shekhar





>



Activitiy Behavior

by Shekhar » Fri, 23 Apr 2010 02:24:09 GMT


 Hi Murphy,

Thanks for your suggestions.

I have a basic querry.suppose all  the three activities are declared
as singletop and suppose from activity A i call
B activity with intent flag as

i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActvity(i)

and from B->C the same intent.Now if i call the activity Aor B from C
with the same intent flag .will the oncreate() function of A,B will be
called again?

If not then it means that the A,B,C are there in the application stack
and their old instance is called again? Am I right?

Thanks,
Shekhar





>



Activitiy Behavior

by Mark Murphy » Fri, 23 Apr 2010 02:29:53 GMT


 


Possibly. Those activities might have been destroyed (e.g., to free up RAM).


AFAIK, yes.

However, bear in mind that the user can press the BACK button, which
will destroy an activity, regardless of singleTop or whatever.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Online Training: 10-14 May 2010:  http://onlc.com 

--



Activitiy Behavior

by faizan khan » Fri, 23 Apr 2010 02:39:21 GMT


 use ViewFlipper whereby you can flip views in the same activity and get the
desired result.






>



Other Threads

1. [WTA] Cable HDMI Evo dan dX.

Halo , numpang tanya yah ... Kalo saya punya cable hdmi bakal droid x , bisa 
dipakai di evo juga ga ?



Thank's

Ary Malik 
 

-- 
===============
"

2. Can I launch executable file under Jni level?

I write some code by c language and build it for arm platform - imx51.
I can run this file under command line like this.

start machine.
adb push ./hello /
adb shell
./hello

and I can see the following information
Hello World!

I write some code on JNI.

#include <jni.h>
#include <stdlib.h>
#include <unistd.h>
#include <utils/Log.h>

JNIEXPORT void JNICALL
Java_rtk_main_atp_BrakeDetect_RunJniBrakeDetect(JNIEnv *env, jobject
jobj)
{
        int ret = execv("/hello", (char *)NULL);

        char buff[100];
        memset(buff, 0, sizeof(100));
        sprintf(buff, "[libhello] Hello %d \n", ret );
        LOGD( buff );

}

but it must have something wrong, because I can't get any result from
logcat.

I got follow message
AndroidRuntime( 2688):
D/AndroidRuntime( 2688): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
D/AndroidRuntime( 2688): CheckJNI is OFF
D/dalvikvm( 2688): creating instr width table
D/AndroidRuntime( 2688): --- registering native functions ---
I/ActivityManager( 2136): Start proc com.android.defcontainer for
service com.android.defcontainer/.DefaultContainerService: pid=2696
uid=10013 gids={1015, 2001}
D/dalvikvm( 2696): GC_EXPLICIT freed 742 objects / 54664 bytes in
53ms
D/PackageParser( 2136): Scanning package: /data/app/vmdl13306.tmp
D/dalvikvm( 2136): GC_FOR_MALLOC freed 6299 objects / 286008 bytes in
105ms
I/PackageManager( 2136): Removing non-system package:rtk.main.atp
I/ActivityManager( 2136): Force stopping package rtk.main.atp
uid=10034
D/dalvikvm( 2136): GC_FOR_MALLOC freed 1619 objects / 115552 bytes in
104ms
D/PackageManager( 2136): Scanning package rtk.main.atp
I/PackageManager( 2136): /data/app/rtk.main.atp-2.apk changed;
unpacking
I/PackageManager( 2136): Package rtk.main.atp codePath changed from /
data/app/rtk.main.atp-1.apk to /data/app/rtk.main.atp-2.apk; Retaining
data and using new
D/installd( 2069): DexInv: --- BEGIN '/data/app/rtk.main.atp-2.apk'
---
D/dalvikvm( 2718): creating instr width table
D/dalvikvm( 2718): DexOpt: load 14ms, verify 6ms, opt 0ms
D/installd( 2069): DexInv: --- END '/data/app/
rtk.main.atp-2.apk' (success) ---
D/PackageManager( 2136):   Activities: rtk.main.atp.BrakeDetect
I/ActivityManager( 2136): Force stopping package rtk.main.atp
uid=10034
W/PackageManager( 2136): Code path for pkg : rtk.main.atp changing
from /data/app/rtk.main.atp-1.apk to /data/app/rtk.main.atp-2.apk
W/PackageManager( 2136): Resource path for pkg : rtk.main.atp changing
from /data/app/rtk.main.atp-1.apk to /data/app/rtk.main.atp-2.apk
D/dalvikvm( 2136): GC_FOR_MALLOC freed 1695 objects / 115832 bytes in
96ms
I/installd( 2069): move /data/dalvik-cache/
d...@app@rtk.main.atp-2....@classes.dex -> /data/dalvik-cache/
d...@app@rtk.main.atp-2....@classes.dex
D/PackageManager( 2136): New package installed in /data/app/
rtk.main.atp-2.apk
D/dalvikvm( 2136): GC_FOR_MALLOC freed 1253 objects / 92008 bytes in
100ms
I/ActivityManager( 2136): Force stopping package rtk.main.atp
uid=10034
D/dalvikvm( 2296): GC_EXPLICIT freed 3866 objects / 240360 bytes in
104ms
W/RecognitionManagerService( 2136): no available voice recognition
services found
D/dalvikvm( 2136): GC_FOR_MALLOC freed 1961 objects / 121864 bytes in
117ms
I/ActivityManager( 2136): Start proc com.svox.pico for broadcast
com.svox.pico/.VoiceDataInstallerReceiver: pid=2720 uid=10014 gids={}
D/dalvikvm( 2136): GC_EXPLICIT freed 412 objects / 21232 bytes in
81ms
I/ActivityThread( 2720): Publishing provider
com.svox.pico.providers.SettingsProvider:
com.svox.pico.providers.SettingsProvider
I/installd( 2069): unlink /data/dalvik-cache/
d...@app@rtk.main.atp-1....@classes.dex
D/AndroidRuntime( 2688): Shutting down VM
D/jdwp    ( 2688): Got wake-up signal, bailing out of select
D/dalvikvm( 2688): De{*filter*} has detached; object registry had 1
entries
D/AndroidRuntime( 2731):
D/AndroidRuntime( 2731): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
D/AndroidRuntime( 2731): CheckJNI is OFF
D/dalvikvm( 2731): creating instr width table
D/AndroidRuntime( 2731): --- registering native functions ---
I/ActivityManager( 2136): Starting activity: Intent
{ act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] flg=0x10000000
cmp=rtk.main.atp/.BrakeDetect }
D/AndroidRuntime( 2731): Shutting down VM
D/jdwp    ( 2731): Got wake-up signal, bailing out of select
D/dalvikvm( 2731): De{*filter*} has detached; object registry had 1
entries
I/ActivityManager( 2136): Start proc rtk.main.atp for activity
rtk.main.atp/.BrakeDetect: pid=2749 uid=10034 gids={}
D/dalvikvm( 2749): No JNI_OnLoad found in /system/lib/
libBrakeDetect.so 0x46123a68, skipping init
I/ActivityManager( 2136): Process rtk.main.atp (pid 2749) has died.
I/ActivityManager( 2136): Displayed activity android/
com.android.internal.app.ResolverA

after I modify some code under JNI

#include <jni.h>
#include <stdlib.h>
#include <unistd.h>
#include <utils/Log.h>

JNIEXPORT void JNICALL
Java_rtk_main_atp_BrakeDetect_RunJniBrakeDetect(JNIEnv *env, jobject
jobj)
{
        int ret = 55;//execv("/hello", (char *)NULL); //fail


        char buff[100];
        memset(buff, 0, sizeof(100));
        sprintf(buff, "[libhello] Hello %d \n", ret );
        LOGD( buff );

}

I got follow message.

D/AndroidRuntime( 2819):
D/AndroidRuntime( 2819): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
D/AndroidRuntime( 2819): CheckJNI is OFF
D/dalvikvm( 2819): creating instr width table
D/AndroidRuntime( 2819): --- registering native functions ---
I/ActivityManager( 2136): Starting activity: Intent
{ act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] flg=0x10000000
cmp=rtk.main.atp/.BrakeDetect }
D/AndroidRuntime( 2819): Shutting down VM
I/ActivityManager( 2136): Start proc rtk.main.atp for activity
rtk.main.atp/.BrakeDetect: pid=2828 uid=10034 gids={}
D/dalvikvm( 2819): De{*filter*} has detached; object registry had 1
entries
D/dalvikvm( 2828): No JNI_OnLoad found in /system/lib/
libBrakeDetect.so 0x46123a68, skipping init
D/        ( 2828): [libhello] Hello 55
I/ActivityManager( 2136): Displayed activity
rtk.main.atp/.BrakeDetect: 335 ms (total 335 ms)
init: starting 'ril-daemon'
- Show quoted text -

and can get the message - "Hello 55" that I want to print to logcat.

Something wrong with execv function?
or
Does anyone know how to launch executable file under JNI level?

-- 

3. HTML5 audio and video support

4. SQLiteDiskIOException in SQLiteDatabase.delete

5. pause AudioTrack correctly

6. Services and battery life

7. How to optimize an "image" app for various devices and screen resolutions