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


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



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


51

Get assets folder files to array of strings Android example | get-assets-folder-files-to-array-of-strings-android-example


Get assets folder files to array of strings.
Its show files in assets folder and sub folders:


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final AssetManager assetManager = getAssets();
        try {
			// for assets folder add empty string
                        String[] filelist = assetManager.list("");
                        // for assets/subFolderInAssets add only subfolder name
                        String[] filelistInSubfolder = assetManager.list("subFolderInAssets");
			if (filelist == null) {
			    // dir does not exist or is not a directory
			} else {
			    for (int i=0; i<filelist.length; i++) {
			        // Get filename of file or directory
			        String filename = filelist[i];
			    }
			}
                     
                        // if(filelistInSubfolder == null) ............  

		} catch (IOException e) {
			e.printStackTrace();
		}
     }


277

SD card SDcard get external storage directory Android | sd-card-get-external-storage-directory-android


Environment.getExternalStorageDirectory()+ File.separator


Boolean canWrite =	Environment.getExternalStorageDirectory().canWrite() ;
if(canWrite){
File f = new File(Environment.getExternalStorageDirectory()
                        + File.separator + "my_image.jpg")
f.createNewFile();
}else{

}

AndroidManifest.xml
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
54

Timer simple TimerTask Java Android example | timer-simple-timertask-java-android-example


TimerTask with updating of TextView here




package cz.okhelp.timer;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TimerActivity extends Activity {
TextView hTextView;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        hTextView = (TextView)findViewById(R.id.idTextView);
        MyTimerTask myTask = new MyTimerTask();
        Timer myTimer = new Timer();
//        public void schedule (TimerTask task, long delay, long period) 
//        Schedule a task for repeated fixed-delay execution after a specific delay.
//
//        Parameters
//        task  the task to schedule. 
//        delay  amount of time in milliseconds before first execution. 
//        period  amount of time in milliseconds between subsequent executions. 

        myTimer.schedule(myTask, 3000, 1500);        
        
    }
class MyTimerTask extends TimerTask {
	  public void run() {
		  // ERROR
		 hTextView.setText("Impossible");
		 // how update TextView in link below  
                 // //android.okhelp.cz/timer-task-timertask-run-cancel-android-example/
                 
	    System.out.println("");
	  }
	}


}


//android.okhelp.cz/asynctask-example-android-with-progressbar/
//android.okhelp.cz/timer-task-timertask-run-cancel-android-example/
395

Unchecked call to add(E) as a member of raw type java.util.List | unchecked-call-to-adde-as-a-member-of-raw-type-java-util-list



// warnning
private List list = new ArrayList();

// ok /put type of added object
private List<String> list = new ArrayList<String>();
212

No Launcher activity found Android Emulator Error | no-launcher-activity-found-android-emulator-error


Error: No Launcher activity found!
The launch will only sync the application package on the device!
Android emulator not showing the app
Workaround:
Check AndroidManifest.xml for MAIN and LAUNCHER. MyActivity.java is first Activity what will opened if .apk is installed.

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name="MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>


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
Share
Share
Tweet