Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

The application may be doing too much work on its main thread


AD MOB

Warning: The application may be doing too much work on its main thread
Try this sorce code:

import android.os.StrictMode;

public class MyActivity extends Activity {
	static{
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy);
	}
	@Override
    public void onCreate(Bundle savedInstanceState) {
//.................. etc.


397LW NO topic_id




AD

Další témata ....(Topics)


328

Screen size density independent pixel resolution | screen-size-density-independent-pixel-resolution


Terms Screen size, density, density independent pixel, resolution as a picture - pictogram.
mobile-phone-screen-resolution-terms

Test your knowledge
Q: How to find out the phone screen size?
A: (By length of display diagonale in inch -  Not to measure a diagonal of device!!!)

Q: What resolution has 720 x 1280 display?
A: (921600 pixels)

Q: What does it mean "240 dpi" screen density?
A: (Display have density 240 x 240  dots - "Tri-color LED etc." - per every physical (real) square inch. If you have icon 240x240 pixels, this will just occupy an area of one square inch on the display.)

Q: Phone have screen density 240 dpi. Image for 160 dpi screen density have size 128x 128 pixels. What will be the size of the image for 240 dpi screen density?
A: (Calculate the virtual pixels size.   128 * (240/160)  =  192.  You have to resize image to new size 192 x 192 physical pixels and put into folder drawable-hdpi (high) ~240dpi  for phone with screen density 240 dpi. ) or use density independend pixels 128dp x 128dp.

 

 
76

If, else if, else statement Java Android example | if-else-if-else-statement-java-android-example


if , else if, else statement with string as a switch statement in Java example source code.

MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "end" };
		for (int i = 0; i < arrayOfString.length; i++) {
			
			if (arrayOfString[i].equals("Hello"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("people"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("hello"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("world!"))
				System.out.println(arrayOfString[i]);
			else // default
				System.out.println("Default");
		}
	}
}
/*
Default
Hello
people
Default
hello
world!
Default 
 */
98

Activity Lifecycle if button Home pressed Android example | activity-lifecycle-if-button-home-pressed-android-example


If on Android emulator home button pressed.

// button home presssed
19:37:06.727: INFO/ActivityManager(60): Starting: 
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] 
flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 60

19:37:06.807: INFO/onSaveInstanceState(339): onSaveInstanceState()
19:37:06.848: INFO/onPause(339): onPause()
19:37:07.968: INFO/onStop(339): onStop()


Diagram of Activity lifecycle if button HOME pressed

life_cycle_button_home_pressed
21

How to install mount SD card for Eclipse Android Emulator | how-install-sd-card-on-android-eclipse-emulator


If you want download some *.apk file from internet and try on your emulator you get error than you have to install SD card. You have to closing Android emulator.
Mount Android emulator SD card instruction

  1. In Eclipse go in menu Window - Android SDK and Avg Manager

  2. Select Virtual devices

  3. Select AVD Name where you need install SD card

  4. Click on Edit button

  5. In open dialog go to SD card - Size: and write 500

  6. Press button Edit AVD

  7. Run AVD emulator


Image how install SD card on Android emulator in Eclipse.



363

How rebuild only one module in project Android Studio | how-rebuild-only-one-module-in-project-android-studio


If you do click on Rebuid project menu item, this operation maybe consume long time on slovly PC.
Some errors dismis when you do rebuild project, or module.
Try this:
Select module where contains red error code and press Debugg or Run button on Android Studio.
If module code contains errors, Android Studio show error report in gradle console.
If not, apk will installed on device.
This is 10 times faster than Clean - Rebuild all project.


Editace: 2013-12-09 10:11:46
Počet článků v kategorii: 397
Url:the-application-may-be-doing-too-much-work-on-its-main-thread

AD
11 Share
Share
Tweet