Some questions about intents and Notepad example

by david » Fri, 09 May 2008 14:19:57 GMT


Sponsored Links
 Since Notepad example is the first classic sample provided by Google,
I think it is worth to study it in close detail.

1. Is it possible for an intent receiver receiving multiple eligible
intents at the same time? If so, what are the priorities associated
with those intents?
Is it possible for an activity receiving multiple eligible intents at
the same time? If so, what are the priorities associated with those
intents?

2. Refer to NotePad/NoteEditor.java/onCreateOptionsMenu() comments. Do
we really need to query system for all activities that implement
ALTERNATIVE_ACTION on the data, and add a menu item for each one that
is found?

3. Where in the code showing the title-editor activity pop-ups a
floated window?

4. In com.google.provider/NotePad.java:

    public static final class Notes implements BaseColumns {
        /**
         * The content:// style URL for this table
         */
        public static final Uri CONTENT_URI
                = Uri.parse("content://com.google.provider.NotePad/
notes");

   where is the "notes" used? What is the purpose of this NotePad.java
file?
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. trying to write to file and failing

hi im just trying to save some text to a file on android and while it
works fine on the emulator "dont crash", when i try it on my phone it
crashes, what am i doing wrong? heres the code:

        try{
            File root = Environment.getExternalStorageDirectory();
            if (root.canWrite()){
                 File file = new File(root, "file.txt");
                 FileWriter writer = new FileWriter(file);
                 BufferedWriter out = new BufferedWriter(writer);
                 out.write("some data");
                 out.close();
                 showMes("File saved.");
             }else{
                 showMes("Could not save file.");
             }
        }catch(Exception e){
            showMes(e.toString());
        }

i do know it crashes on " File root =
Environment.getExternalStorageDirectory(); " i just dont know why.
showMes() is just a function to make toast. thanks for any help.

-- 

2. My app crashes upon relaunch

Environment:
- Windows XP box
- Eclipse with ADT 9.6
- Test Devices: Droid and Eris

I am putting the finishing touches on a new game -- my first Android
app.  The last big problem I am having is as follows.

After launching the app from the home screen, using and exiting,
*relaunching* the app from the home screen generates an exception.
Looking at LogCat shows the following error: "ERROR/dalvikvm-
heap(25501): 1728000-byte external allocation too large for this
process."  Pressing [Force Close] closes the app.  The 3rd attempt to
run is successful.

What I Know:

- The app properly handles the [HOME] button, i.e. disappears and
reappears at the user's discretion.

- The app has two activities: Intro and Game

- The Intro activity has MAIN and LAUNCHER attributes in manifest.  It
does very few allocations but does have a couple screen-sized bitmaps
that are displayed.  When the user is ready to move to the Game
activity, the Game activity is started and the Intro activity is
finished (onDestroy() is called).

- The Game activity has many allocations of all sizes.  I know I am
cruising near the max amount of allocations because I am constantly
refactoring the app to find ways to creatively stay within memory
limits.  The Game activity has a thread that runs for the life of the
activity.  When the user ends the app with the BACK key the app starts
its clean-up.  The thread appears to be properly finishing as does the
activity (onDestroy() is called).  The app's onTerminate() method is
never called (based on my hours of searching for answers, it's seems
this is okay).

- I was having memory limit problems a couple weeks ago and that was
the reason I divided a single activity into two activities.  I was
surprised that this, alone, did not solve my problem.  Within the
Intro Activity (which, as I stated, appears to be finishing properly)
I had explicitly set the only view's background to null since it has a
big bitmap.  This worked but was a surprising solution since I thought
the View object, etc. would all be GC'ed when the activity finished,
so I am uneasy about it as a long-term solution.

- At this point I am suspicious of two things: memory leaks and
improper management of app/activity life cycle.

- Memory Leaks: I have done pretty deep memory leak debugging in the
past in the C++/Windows world.  In the Android/Eclipse world, I am a
novice.  I have gotten as far as getting the Allocation Tracker to
show up in Eclipse.  I have not been successful in getting it to
display allocations for the app.

Improper App/Activity Life Cycle: I *think* I'm doing all the right
things but obviously I am not.  My assumption originally was the the
app's onTerminate() was where I should clean up global items.  Since
it's not being called, I moved that clean-up to Game activity.  I have
tried a variety of Activity attributes (such as "Finish on Task
Launch") with no success.  Admittedly, I am trying these but not with
confidence in my understanding of what the all, exactly, mean.

- The location of the memory allocation is noted in the code snippet
below.  What's odd is that app's onCreate() is only called during the
first launch, not the 2nd.

Thank you for your help.

Tom

====== Intro Activity's onCreate() =========

  @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Log.i("Tom", "IntroActivity.onCreate()");

        setContentView(R.layout.intro);         <------------ Causes
Crash

        Log.i("Tom", "m_app = " + m_app);
        m_app = BasketballApp.GetInstance();
        Log.i("Tom", "m_app = " + m_app);
        :
    }

====== Custom LogCat Dump =========

-- 1st Launch
05-03 16:36:46.483: INFO/Tom(25670): app.onCreate()
05-03 16:36:46.491: INFO/Tom(25670):    - Looks like App is starting
fresh
05-03 16:36:46.507: INFO/Tom(25670): IntroActivity.onCreate()
05-03 16:36:47.202: INFO/Tom(25670): m_app = null
05-03 16:36:47.202: INFO/Tom(25670): m_app =
lizardtap.basketball1.basketball...@447bf8a8
05-03 16:36:59.124: INFO/Tom(25670): Activity: onCreate()
05-03 16:36:59.460: INFO/Tom(25670): GameView $
05-03 16:36:59.460: INFO/Tom(25670): BasketballThread $()
05-03 16:37:00.710: INFO/Tom(25670): Activity: onStart()
05-03 16:37:00.710: INFO/Tom(25670): Activity: onResume()
05-03 16:37:00.882: INFO/Tom(25670): IntroActivity.onDestroy()
05-03 16:37:09.616: INFO/Tom(25670): surfaceCreated()
05-03 16:37:09.616: INFO/Tom(25670): startGameThread()
05-03 16:37:09.616: INFO/Tom(25670): freezeGameThread()
05-03 16:37:09.616: INFO/Tom(25670): setSurfaceSize()
05-03 16:37:09.655: INFO/Tom(25670): thread.run {start}
05-03 16:37:09.710: INFO/Tom(25670): _setSurfaceSize() end
05-03 16:37:20.147: INFO/Tom(25670): Activity: onPause()
05-03 16:37:20.303: INFO/Tom(25670): surfaceDestroyed()
05-03 16:37:20.311: INFO/Tom(25670): freezeGameThread()
05-03 16:37:20.585: INFO/Tom(25670): Activity: onStop()
05-03 16:37:20.585: INFO/Tom(25670): Activity: onDestroy()
05-03 16:37:20.593: INFO/Tom(25670): stopGameThread()
05-03 16:37:20.616: INFO/Tom(25670): thread.run {end}
-- 2nd Launch
05-03 16:37:22.522: INFO/Tom(25670): IntroActivity.onCreate()    <----
notice not preceded by app.onCreate()

-- 

3. Something wrong here, didn't expect com.commonsware.android.rotation.two to be resumed

4. Linkify-ed TextView non-linked text disappears on touch

5. No Phone Signal in Emulator (2.1)

6. catching both click and long click on a ListView

7. Test Kecepatan PUSH MAIL dari 3 Provider pada 3 Handset Berbeda dengan 2 Operating Sytem yang berbeda pula.