Big thanks for pointing to this useful debugging feature ("adb
logcat"). I have fixed the problem.
As I suspected, the context is a system service, which is not suitable
to start an intent activity. And the error message actually gives a
clue on the fix, which is to add FLAG_ACTIVITY_NEW_TASK flag.
Below is the new snippet that works to make the record complete. I
also attached the related log output.
Cheers.
Jun
-------------------
void showRecentAppsDialog() {
// [jsun]
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://192.168.0.1/"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(i);
/*
if (mRecentAppsDialog == null) {
mRecentAppsDialog = new RecentApplicationsDialog(mContext);
}
mRecentAppsDialog.show();
*/
}
-------------------
W/dalvikvm( 76): threadid=39: thread exiting with uncaught exception
(group=0x4001da28)^M
E/AndroidRuntime( 76): Uncaught handler: thread WindowManagerPolicy
exiting due to uncaught exception^M
E/AndroidRuntime( 76): *** EXCEPTION IN SYSTEM PROCESS. System will crash.^M
I/ActivityManager( 76): Start proc com.android.settings for
broadcast com.android.settings/.widget.SettingsAppWidgetProvider:
pid=253 uid=1000 gids={3002, 3001, 3003}^M
E/AndroidRuntime( 76): android.util.AndroidRuntimeException: Calling
startActivity() from outside of an Activity context requires the
FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?^M
E/AndroidRuntime( 76): at
android.app.ApplicationContext.startActivity(ApplicationContext.java:649)^M
E/AndroidRuntime( 76): at
com.android.internal.policy.impl.PhoneWindowManager.showRecentAppsDialog(PhoneWindowManager.java:425)^M
E/AndroidRuntime( 76): at
com.android.internal.policy.impl.PhoneWindowManager$2.run(PhoneWindowManager.java:416)^M
E/AndroidRuntime( 76): at
android.os.Handler.handleCallback(Handler.java:587)^M
E/AndroidRuntime( 76): at
android.os.Handler.dispatchMessage(Handler.java:92)^M
E/AndroidRuntime( 76): at android.os.Looper.loop(Looper.java:123)^M
E/AndroidRuntime( 76): at
com.android.server.WindowManagerService$PolicyThread.run(WindowManagerService.java:509)^M
I/Process ( 76): Sending signal. PID: 76 SIG: 9^M
...
On Sat, Jan 23, 2010 at 2:52 PM, Dianne Hackborn <[email protected]> wrote:
> It's in the logcat output.
>
> On Fri, Jan 22, 2010 at 10:28 PM, Jun Sun <[email protected]> wrote:
>>
>> How can I find out the stack? Is it dumped somewhere in the file system?
>>
>> One thing I have been suspecting is that the mContext of
>> PhoneWindowManager may not be a normal app content to launch an activity,
>> but I am sure someone else should know better ... :)
>>
>> Cheers.
>>
>> jun
>>
>> Dianne Hackborn wrote:
>>>
>>> Well what is the stack crawl when it crashes?
>>>
>>> On Fri, Jan 22, 2010 at 3:27 PM, Jun Sun <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>> My goal is to launch web browser when I press the HOME key *when*
>>> phone is already at home page.
>>>
>>> Since this is hard (for me anyway), my first shot is to modify the
>>> HOME key long-press behavior so that it will launch the web browser.
>>>
>>> Thanks to Fei Zhang, who has correctly pointed me to the
>>> PhoneWindowManager.java file, I am able to locate the right place
>>> and inject the code to launch browser. See the code snippet below.
>>>
>>> Unfortunately, it does not work. If I do long-press twice, the whole
>>> UI interface resets (re-starting from flickering "ANDROID" logo).
>>> Does anybody have any ideas? I'd really appreciate.
>>>
>>> My device is ADP1. My tree is donut branch. My build host is FC11.
>>>
>>> Cheers.
>>>
>>> Jun
>>>
>>> --------------------
>>> PhoneWindowManager.java:
>>>
>>> ...
>>>
>>> Runnable mHomeLongPress = new Runnable() {
>>> public void run() {
>>> /*
>>> * Eat the longpress so it won't dismiss the recent apps
>>> dialog when
>>> * the user lets go of the home key
>>> */
>>> mHomePressed = false;
>>> performHapticFeedbackLw(null,
>>> HapticFeedbackConstants.LONG_PRESS, false);
>>> sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
>>> showRecentAppsDialog();
>>> }
>>> };
>>>
>>> void showRecentAppsDialog() {
>>> /* [jsun] */
>>> mContext.startActivity(new Intent(Intent.ACTION_VIEW,
>>> Uri.parse("http://m.google.com/")));
>>> /*
>>> if (mRecentAppsDialog == null) {
>>> mRecentAppsDialog = new RecentApplicationsDialog(mContext);
>>> }
>>> mRecentAppsDialog.show();
>>> */
>>> }
>>>
>>> -- unsubscribe: [email protected]
>>> <mailto:android-porting%[email protected]>
>>> website: http://groups.google.com/group/android-porting
>>>
>>>
>>>
>>>
>>> --
>>> Dianne Hackborn
>>> Android framework engineer
>>> [email protected] <mailto:[email protected]>
>>>
>>> Note: please don't send private questions to me, as I don't have time to
>>> provide private support, and so won't reply to such e-mails. All such
>>> questions should be posted on public forums, where I and others can see and
>>> answer them.
>>>
>>> --
>>> unsubscribe: [email protected]
>>> website: http://groups.google.com/group/android-porting
>>
>> --
>> unsubscribe: [email protected]
>> website: http://groups.google.com/group/android-porting
>
>
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails. All such
> questions should be posted on public forums, where I and others can see and
> answer them.
>
> --
> unsubscribe: [email protected]
> website: http://groups.google.com/group/android-porting
--
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting