这是一个奇怪的问题,我的意图是不能在Android 4.0+设备的情况下切换活动,但是,在Android 2.2 / 2.3的设备上,它工作正常。
这就是我为我的类PhotoActivity定义意图的方法。
public static final void startActivityForResult(Activity parent, int requestCode, String userName, String photoUrl, Bitmap preview, boolean isMugshot) {
System.out.println("photoactivity started" +requestCode+"second"+parent);
Intent intent = new Intent(parent, PhotoActivity.class)
.putExtra(USERNAME, userName)
.putExtra(PHOTOURL, photoUrl)
.putExtra(PREVIEW, preview)
.putExtra(IS_MUGSHOT, isMugshot);
parent.startActivityForResult(intent, requestCode);
}
我想根据特定的用户触摸响应从另一个类切换到上面的活动类。我将其定义如下
case R.id.ImgAvatar:
PhotoActivity.startActivityForResult(this, REQUEST_SHOW_AVATOR, mUserName, avatarUrl, mAvatar, true);
break;
我的代码很好,因为在android 2.3 / 2.2的情况下,我可以在行为之间切换。但是,在使用带有android 4.0+的设备时,我不会在触摸响应之间切换活动,而是恢复到我的主要活动(无知为什么)。
我还注意到2.2和4.0版本的控制台输出不同。我仍然无法猜到为什么android 4.0会造成麻烦。
这是活动正常启动时的日志(android 2.2 / 2.3),
04-11 10:29:21.665: I/System.out(924): photoactivity started userdhttp://www.l-somewhere.com/media/Users/a6cb0167255045a9a2a16bb3411bc2/Mugshot/324c3a02b252428b8676e42671e392c2.jpg
04-11 10:29:21.675: I/System.out(924): photoactivity started4096secondcom.lsomewhere.android.UserDataActivity@44ae2b80
04-11 10:29:21.845: D/dalvikvm(924): GC_EXTERNAL_ALLOC freed 1481 objects / 289856 bytes in 84ms
04-11 10:29:21.855: I/PhotoActivity(924): onCreate// **rightly called** ,switch of activity
04-11 10:29:21.855: I/pthread(924): ## thread 924 is creating thread @dalvik/vm/Thread.c:1443
04-11 10:29:21.855: I/pthread(924): ## thread 1008 is created success
04-11 10:29:25.325: D/dalvikvm(938): GC_FOR_MALLOC freed 1339 objects / 483712 bytes in 69ms
这是android 4.0 +
的日志04-11 10:34:47.415: I/System.out(22717): photoactivity started userdhttp://www.l-somewhere.com/media/Users/a6cb0167255045a9a2a16bb3411bc2/Mugshot/324c3a02b252428b8676e42671e392c2.jpg
04-11 10:34:47.420: I/System.out(22717): photoactivity started4096secondcom.lsomewhere.android.UserDataActivity@424d6db0
04-11 10:34:47.520: D/SensorManager(22717): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@4201ce20
04-11 10:34:47.525: D/Sensors(22717): Remain listener = Sending .. normal delay 200ms
04-11 10:34:47.525: I/Sensors(22717): sendDelay --- 200000000
04-11 10:34:47.525: D/SensorManager(22717): JNI - sendDelay
04-11 10:34:47.525: I/SensorManager(22717): Set normal delay = true
04-11 10:34:47.745: D/dalvikvm(24379): GC_CONCURRENT freed 184K, 10% free 12467K/13703K, paused 3ms+12ms, total 29ms
04-11 10:34:47.750: W/CursorWrapperInner(24379): Cursor finalized without prior close()
04-11 10:34:47.775: I/MainActivity(24379): RegistrationId, DeviceTocken: //**I don't know why rather than starting the photo activity, the main activity is called,**
显然,在android 4.0+的情况下,我的第二个活动没有被调用,我被恢复为主要活动。另一个有趣的观察是实际调用了intent,即我达到了我定义intent的函数,但似乎intent无法启动活动,因此intent会运行但它无法启动新活动。我很无能,因为我的代码没有给出任何运行/编译时错误,因此很难找出问题所在。感谢帮助。
这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lsomewhere.android"
android:versionCode="37"
android:versionName="1.0.37" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.lsomewhere.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.lsomewhere.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:icon="@drawable/ic_launcher_72x72"
android:label="@string/app_name" >
<uses-library
android:name="com.google.android.maps"
android:required="true" />
<service
android:name=".LsCommService"
android:process=":apisrv" >
<intent-filter>
<action android:name="com.lsomewhere.android.LSAPISERVICE" />
</intent-filter>
</service>
<service android:name=".GCMIntentService" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.lsomewhere.android" />
</intent-filter>
</receiver>
<activity
android:name=".SplashActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/login"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="stateUnspecified|adjustPan" >
</activity>
<activity
android:name=".ProfileActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/login"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name=".AvatarActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/upload_your_photo"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".UserDataActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/user_data"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name=".GalleryActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar"
>
</activity>
<activity
android:name=".PhotoActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar"
>
</activity>
<activity
android:name=".PasswordActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="stateVisible" >
</activity>
<activity
android:name=".AboutActivity"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name=".AdvrDataActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name=".PageBase"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
<activity android:name="com.lsomewhere.android.TutorialActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation"></activity>
<activity android:name="com.kuad.ADDisplay"/>
</application>