Problems encountered in Android development "eight"

Source: Internet
Author: User

I. Tool use 245. When using Androidstudio, I don't know why SVN's gone.

Android Studio missing Subversion plugin

Sure the "subversionintegration" plugin is enabled in Preferences > Plugins

248.androidstudio How to automatically import the class or interface used?
For Windows/Linux, you can go to File -> Settings -> Editor -> General -> Auto Import -> Java and make the following changes:change Insert imports on paste value to AllmarkAdd unambigious imports on the fly option as checkedOn a Mac, do the same thing in Android Studio -> Preferences

Reference is the "shortcut to Auto Import all" in Android Studio?

251. Remove the. SvN method under Ubuntu
find -type d -name ‘.svn‘ -exec rm -rfv {} \;参考 http://blog.csdn.net/zhaoyu7777777/article/details/9445717
252. Fatal:could not read from remote repository.

Git configuration, the public key has been sent to the server, the terminal command line can also be normal pull push, but the androidstudio push or pull when the above error occurs
How to Solve
Setting–> Version Control–>git, in the SSH executable dropdown, choose Native

258. The following occurs after the root of the mobile phone Android:adb:copy file To/system (Permission denied)

Solution, Need Remount/system
Mount-o Remount,rw/system

261.anroid several very good shortcut keys
    1. Ctrl+shift+alt+t Refactoring Code change name
    2. Ctrl+i Horizontal Split-screen display "need to search for split in Keymap to set the shortcut for Move right"
    3. Shift+alt+l variable Generation
    4. CTRL+SHIFT+V automatic generation of variables
    5. Ctrl+o viewing functions in a file
    6. Ctrl+shift+t or Ctrl+shift+r Fuzzy Lookup class
    7. Ctrl+e View Toggle recently opened files
Two. Java and Android Basics 246.error:execution failed for task ': App:dexdebug ' .> Com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process ' Command '/ Home/xxx/tools/android/jdk1.7.0_71/bin/java "finished with Non-zero exit value 2

Check if the same jar package is referenced more than once
Following conditions
1. Module under the JAR package version is different

    1. The same module contains the Le. jar in the Libs, and the corresponding source page is added under SRC

    2. Whether the compilation is repeated in the Gradle,

Like what
Compile Filetree has been added (include: [' *.jar '], dir: ' Libs ')
However, in the following add a sentence compile files (' Libs/xxx.jar ')

Refer to Error:execution failed for task ': App:dexdebug '. Com.android.ide.common.process.ProcessException

249.Android ndk:could not find application project directory! Android ndk:please define the Ndk_project_path variable to the it.
/home/cenuser/android/android-ndk-r7b/build/core/build-local.mk:130: *** Android NDK: Aborting    .  Stop.cd到jni目录。或者 ndk-build -C your_project_path
How to set RadioButton to the right of the text in 256.Android, icon on the left

Workaround:
The first step:
Android:button= "@null" This statement hides the original system's RadioButton icon.
Step Two:
android:drawableright= "@android:d rawable/btn_radio" statement
Reference http://blog.csdn.net/sunnyfans/article/details/7901592

257.java report "Illegal character: \65279" error resolution

As we all know, in the cross-program engineering, unified coding is very important, and the most common is the unified use of "UTF8" coding scheme.
But when using the UTF8 scheme, be aware of the editor's cleverness.
Like EditPlus.
The reason is that some editors add the UTF8 tag to the UTF8 file (EditPlus called it a signature), which inserts three invisible characters (0xEF 0xBB 0xBF, or BOM) at the beginning of the file, which represents a Unicode tag (BOM).
Reference http://hyl198611.iteye.com/blog/1336981

260.android Double-click Back to exit
 Public  class mainactivity extends Activity {    PrivateToast Toast;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main); Toast = Toast.maketext (Getapplicationcontext (),"OK exit?" ",0); } Public void onbackpressed() {quittoast (); }Private void Quittoast() {if(NULL= = Toast.getview (). GetParent ()) {toast.show (); }Else{System.exit (0); }    }}

Or

PrivateToast Toast;protected void onCreate(Bundle savedinstancestate) {... toast = Toast.maketext ( This,"Press again to exit the app", Toast.length_short); Toast.setgravity (Gravity.bottom,0, conversionutil.dip2px ( This, Max)); }@Override  Public void onbackpressed() {if(doublebacktoexitpressedonce) {if(toast!=NULL) {toast.cancel (); }Super. onbackpressed ();return; } This. doublebacktoexitpressedonce =true; Toast.show ();NewHandler (). postdelayed (NewRunnable () {@Override          Public void Run() {doublebacktoexitpressedonce=false; }     }, -); }

Refer to Android for dual Knockback app issues

262. The following issues occurred when introducing Android Materialdesign in the old project

Android.view.InflateException:Binary XML file line #17: Error inflating class Android.support.design.internal.NavigationMenuView
caused by:java.lang.reflect.InvocationTargetException
caused By:android.content.res.resources$notfoundexception:resource is not a drawable (color or path): typedvalue{t=0x2/ D=0X7F0100C5 A=-1}
You need to use a theme.appcompat Theme (or descendant) with the this activity.

Workaround: Use Navigationmenuview's activity "generally mainactivity" inherited from Appcompatactivity, and modify the Theme for the activity in Androidmanifest.xml, using the theme inherited from @style/theme.appcompat.

262.How to get key and value of HashMap in Java
 Public  class accesskeyvalueofhashmap {         Public Static void Main(string[] args) {//Create a Empty HashMaphashmap<string, string> obhashmap =NewHashmap<string, string> ();//Put values in hash mapObhashmap.put ("AB","1"); Obhashmap.put ("EF","2"); Obhashmap.put ("Gh","3"); Obhashmap.put ("CD","4");//store Entry (key/value) of HashMap in setSet mapset = (set) Obhashmap.entryset ();//create iterator on SetIterator mapiterator = Mapset.iterator (); System.out.println ("Display the Key/value of HashMap."); while(Mapiterator.hasnext ()) {Map.entry mapentry = (map.entry) mapiterator.next ();//GetKey Method of HASHMAP access a key of mapString keyValue = (string) mapentry.getkey ();//getvalue method returns corresponding key ' s valueString value = (string) mapentry.getvalue (); System.out.println ("Key:"+ KeyValue +"= Value:"+ value); }        }}
Three. Android performance 246.android Handler warning handler Class should be Static or Leaks occur

When using handler to update the UI, the public class Sampleactivity extends Activity {

Private final Handler Mleakyhandler = new Handler () {
@Override
public void Handlemessage (Message msg) {
Todo
}
}
} will package the above warning will cause a memory leak
The reason is that the anonymous inner class handler holds the activity reference, and when the activity finishes handler not finished, the view and resource resources of the activity cannot be released, resulting in a memory leak
Google officially gives the right approach to this issue
Handled by a static inner class that contains a weak reference to activity.
public class Sampleactivity extends Activity {

/**
* Instances of static inner classes do not hold a implicit
* Reference to their outer class.
*/
private static class MyHandler extends Handler {
Private final WeakReference mactivity;

public MyHandler(SampleActivity activity) {  mActivity = new WeakReference<SampleActivity>(activity);}@Overridepublic void handleMessage(Message msg) {  SampleActivity activity = mActivity.get();  if (activity != null) {    // ...  }}

}

Private final MyHandler Mhandler = new MyHandler (this);

/**
* Instances of anonymous classes don't hold a implicit
* Reference to their outer class when they is "static".
*/
private static final Runnable srunnable = new Runnable () {
@Override
public void Run () {}
};

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);

// Post a message and delay its execution for 10 minutes.mHandler.postDelayed(sRunnable, 60 * 10 * 1000);// Go back to the previous Activity.finish();

}
}

Refer to Android handler warning handler Class should be Static or Leaks occur

250. Why does I want to avoid non-default constructors in fragments? Fragment setting the correct procedure for parameters
Make a bundle object and insert your data (in this example your Category object). Be careful, you can‘t pass this object directly into the bundle, unless it‘s serializable. I think it‘s better to build your object in the fragment, and put only an id or something else into bundle. This is the code to create and attach a bundle:Bundle args = new Bundle();args.putLong("key", value);yourFragment.setArguments(args);After that, in your fragment access data:Type value = getArguments().getType("key");That‘s all.
Four. Code obfuscation 255. Code obfuscation times the following error error:execution failed for task ': App:proguarxxxrelease '.

Java.io.IOException:Can ' t read [/libs/xxx.jar] (No such file or directory)
Http://stackoverflow.com/questions/26028171/android-studio-proguard-java-io-ioexception-bin-classes-no-such-file-or-d

Solution proguard-android.txt files are not used in the designation-injars,-outjars, Or-libraryjars or libs.

The Android Gradle plugin already specifies all input and output for your, so do must not Specify-injars,-outjars, or-l Ibraryjars.

Moreover, the file Proguard-android.txt in the "Android SDK specifies all generic Android settings for your, so you shouldn ' T specify them again.

Essentially, your file proguard-rules.txt can be empty, except-any application-specific settings-make sure any REFL Ection continues to work

Four. 243. The importance of the architect in writing the detailed design.

Detailed design, this is the test of technical experts design thinking of an important level, detailed design specification should be the most ' clean ' way (black box structure) to the coder, so that the overall modular system to achieve maximum; a good detailed design manual can reduce the complexity of coding to a minimum, in fact, Strictly speaking detailed design instructions should be each function of each parameter definition is refined and carefully provided, from the requirements analysis to the outline design to complete the detailed design specification, a software project should be said to complete half. In other words, when a large software system is halfway through, it does not actually start a single line of code work.

More questions please focus on Android development problems

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Problems encountered in Android development "eight"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.