项目中用到 AsyncTask 里面方法不执行,求高手来解决

Android 码拜 9年前 (2015-11-15) 1086次浏览
项目中用到 AsyncTask  当从一个activity直接调转到 VideoPlayActivity  这个activity中方法可以正常进去执行,没有一点问题
intent_first.putExtra(“userType”, “parent”);
intent_first.setClass(MainActivity.this, MainStudentMangerActivity.class);
intent_first.setClass(MainActivity.this, VideoPlayActivity.class);
startActivity(intent_first);
但是  本人从 GridTextAdapter  中 跳转到 VideoPlayActivity   ,AsyncTask   里面的方法就不执行。
Intent intent = new Intent();
intent.putExtra(“iamgeId”, String.valueOf(position)+””);
intent.setClass(mContext, VideoPlayActivity.class);
v.getContext().startActivity(intent);
下面是  AsyncTask 方法

class PlayAsyncTask extends AsyncTask<String, Integer, String> {
		@Override
		protected String doInBackground(String... params) {
			// PLAY
			initVideoView();
			return null;
		}
		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			if (mPath.startsWith("http:"))
				mVideoView.setVideoURI(Uri.parse(mPath));
			else
				mVideoView.setVideoPath(mPath);
			// 设置显示名称
			mMediaController = new MediaController(VideoPlayActivity.this, mVideoView);
			mMediaController.setmPlayControl(mPlayControll);
			mMediaController.setOnPauseListener(mPauseListener);
			mVideoView.setMediaController(mMediaController);
			mMediaController.setFileName("哈哈哈");

			int mCurrentOrientation = getResources().getConfiguration().orientation;
			if (mCurrentOrientation == Configuration.ORIENTATION_PORTRAIT) {
				Utils.full(false, VideoPlayActivity.this);
				mRl_PlayView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 400));
				if (mVideoView != null){
//					mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
					}
			} else if (mCurrentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
				Utils.full(true, VideoPlayActivity.this);
				mRl_PlayView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
				if (mVideoView != null)
					mVideoView.setVideoLayout(mLayout, 0);
			}
			mVideoView.requestFocus();
			mGestureDetector = new GestureDetector(new MyGestureListener());
		}
	}
解决方案:20分
所以你貼錯東西了, 你要看的是兩個activity之間有什麼不同
假如呼叫了execute不執行
那有沒有試過executeOnExecutor
有可能你有多個asynctask  所以導致thread卡住

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明项目中用到 AsyncTask 里面方法不执行,求高手来解决
喜欢 (0)
[1034331897@qq.com]
分享 (0)