Android novice cross the river by feeling the stones

All systems have unspoken rules, and android development is no exception. Novices need to spend some time solving inexplicable problems, so I will record them here.

(1) Development tools: adt-bundle-windows-x86-20130219

(2) The compilation is correct, but the runtime reports an error:

UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added

...

Conversion to Dalvik format failed with error 1

I know the problem is that there are two identical classes when packaged, but I don't know how to repeat them, because my jar package only introduces one. Only later found out that libs->Build path->Use as source Folder was a stupid mistake, removing it solved the problem.

(3) Installing maven is very laborious, http://blog.csdn.net/cai5/article/details/7328422

Following this step does not work, there is a problem when installing svn, and then directly download the plugin installation package, unzip it to eclipse, and then you can install maven.

(4) The libs directory will be automatically packaged into apk.

(5) The smoothest way to switch fragments, instead of attach and detach, use hide and show

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		if (mCurTransaction == null) {
			mCurTransaction = mFragmentManager.beginTransaction();
		}

		// Do we already have this fragment?
		String name = makeFragmentName(container.getId(), position);
		Fragment fragment = mFragmentManager.findFragmentByTag(name);
		if (fragment != null) {
			if (DEBUG)
				Log.v(TAG, "Attaching item #" + position + ": f=" + fragment);
			// mCurTransaction.attach(fragment);
			mCurTransaction.show(fragment);
		} else {
			fragment = getItem(position);
			if (DEBUG)
				Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
			mCurTransaction.add(container.getId(), fragment, makeFragmentName(container.getId(), position));
		}
		if (fragment != mCurrentPrimaryItem) {
			fragment.setMenuVisibility(false);
			fragment.setUserVisibleHint(false);
		}

		return fragment;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {

		if (mCurTransaction == null) {
			mCurTransaction = mFragmentManager.beginTransaction();
		}
		if (DEBUG)
			Log.v(TAG, "Detaching item #" + position + ": f=" + object + " v=" + ((Fragment) object).getView());
//		mCurTransaction.detach((Fragment) object);
		mCurTransaction.hide((Fragment) object);
	}

 

 (6) The program running OK on the 4.0 version encounters a problem on the 2.3 platform. After copying the database and opening it, the database opening error is always reported. The final solution is to use the manager of the sqlite3.6.22 version to create the database, and then import the higher version SQL statement, redeployed to Android 2.3 successfully.

(7) There is a problem with taking pictures from Xiaomi mobile phones, but other mobile phones have no problem. Solution: When saving, rebuild your own file name and not put it in the system picture directory.

		Intent intent = new Intent();
		intent.setAction(Intent.ACTION_GET_CONTENT);
		intent.setType("image/*");
		intent.putExtra("crop", "true");
		intent.putExtra("aspectX", aspectX);
		intent.putExtra("aspectY", aspectY);
		// outputX outputY is the width and height of the cropped image
		intent.putExtra("noFaceDetection", true);
		//File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "temp");
		File mediaStorageDir = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + "myapp" + File.separator+ "temp");
		outputImageFile = mediaStorageDir;

		intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outputImageFile));
		activity.startActivityForResult(intent, REQUEST_CODE_SELECT_PHOTO);

 

(8) The problem of multi-selection jumping in the millet list

      It can be solved by removing the code: //lvContent.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326936096&siteId=291194637