The Android Application Framework FAQ states:
"The general mechanism to start a new activity if its not running— or
to bring the activity stack to the front if is already running in the
background— is the to use the NEW_TASK_LAUNCH flag in the startActivity
() call."

I have some fairly simple code that allows the user to switch between
running tasks.  Most of the time things work fine, but there a few
scenarios that cause my program to crash.

First, here is the code that I am using to bring a "running" activity
to the foreground:

ActivityManager.RunningTaskInfo task = getTask(idx);
if (task != null)
{
        Intent intent = new Intent();
        intent.setClassName(task.topActivity.getPackageName(),
task.topActivity.getClassName());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        try
        {
                m_context.startActivity(intent);
        }
        catch (ActivityNotFoundException e)
        {
                Toast.makeText(m_context, "Unable to launch activity...",
Toast.LENGTH_SHORT).show();
        }
}

- Crash Scenario 1:
Switching to any task in the list of running task that has started
another activity (i.e. task.topActivity and task.baseActivity are
different) causes a crash.  I have tried the code above using both
task.topActivity and task.baseActivity but the results are the same...
force close.

- Crash Scenario 2:
Switching to specific tasks always causes a force close.  For example,
when I try to switch to the Calendar Task when it is "running" my
program always crashes.  However, I can successfully switch to Google
Maps, Home, Browser, and most others.

For the Calendar Task, I am getting "com.android.calendar.DayActivity"
and the class name and "com.android.calendar" as the package name.
When running the Eclipse Debugger, I get a new tab that pops up in
Eclipse when executing the m_context.startActivity(intent); line...
The title in the tab says "ViewRoot.handleMessage(Message) line: 1583"
and in the tab is text in red that says "Source not found" and a
button that says "Edit Source Lookup Path"

I'm very baffled here and have not been able to find anything online
or in the google groups regarding this issue.  I hope that someone has
an idea of what I am doing wrong.  There are other task switcher
applications available on the Android Market that do not have this
problem.

Thanks in advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to