Example usage for android.os StrictMode setThreadPolicy

List of usage examples for android.os StrictMode setThreadPolicy

Introduction

In this page you can find the example usage for android.os StrictMode setThreadPolicy.

Prototype

public static void setThreadPolicy(final ThreadPolicy policy) 

Source Link

Document

Sets the policy for what actions on the current thread should be detected, as well as the penalty if such actions occur.

Usage

From source file:com.moods_final.moods.entertainment.YouTubeAPIDemoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.topics);//from w  ww  . j  ava2s. c o  m
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    lvTopics = (ListView) findViewById(R.id.topics);

    //AsyncTaskRunner runner = new AsyncTaskRunner();

    //runner.execute();
    try {
        lvTopics.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, this.getTopics()));
    } catch (IOException e) {
        e.printStackTrace();
    }

    lvTopics.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {

            //Take action here.
            Log.e("pressed", ":" + topics.get(position).toString());

            Intent intent = new Intent().putExtra("chId", topid.get(position).toString());
            ;
            intent.setComponent(new ComponentName(getPackageName(),
                    "com.moods_final.moods.entertainment.ChannelListActivity"));
            startActivity(intent);

        }

    });

}

From source file:com.github.punkboy.ampdroid.ui.AMPDroidBaseActivity.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private final void StrictModePermitAll() {
    StrictMode.setThreadPolicy((new android.os.StrictMode.ThreadPolicy.Builder()).permitAll().build());
    Log.d(TAG_BASE, "StrictMode is Currently set to PermitAll");
}

From source file:com.oakclub.android.base.OakClubApplication.java

@SuppressWarnings("unused")
@Override/*from   w w w  .j  a  va 2 s .c  o m*/
public void onCreate() {
    if (Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
    }

    super.onCreate();
    pingActivities();
    initImageLoader(getApplicationContext());

}

From source file:com.example.georg.theupub.UpubInfo.java

public void getInfo() throws SQLException, ClassNotFoundException {
    boolean flag = true;
    Connection conn = null;// ww  w .j  av a  2s. c om
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    String dbURL = "jdbc:jtds:sqlserver://apollo.in.cs.ucy.ac.cy:1433";
    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Properties properties = new Properties();
    properties.put("user", "upub");
    properties.put("password", "XuZ3drup");
    properties.put("databaseName", "upub");
    try {
        conn = DriverManager.getConnection(dbURL, properties);
    } catch (SQLException e) {
        flag = false;
        Context context = getApplicationContext();
        CharSequence text = "Cannot connect to DataBase. Info may not be up to date!";
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
    if (flag) {
        String SQL = "Select * From [dbo].[Info]";
        System.out.print("done!");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(SQL);
        if (rs.next()) {
            final TextView Address = (TextView) findViewById(R.id.Andress);
            Address.setText(rs.getString(1));
            final TextView OpenHours = (TextView) findViewById(R.id.OpenHours);
            OpenHours.setText(rs.getString(2));
            final TextView phone = (TextView) findViewById(R.id.Telephone);
            phone.setText(rs.getString(3));
            final TextView email = (TextView) findViewById(R.id.Email);
            email.setText(rs.getString(4));
            final TextView services = (TextView) findViewById(R.id.Services);
            services.setText(rs.getString(5));
            final TextView Managers = (TextView) findViewById(R.id.Managers);
            Managers.setText(rs.getString(6));
            final TextView Parking = (TextView) findViewById(R.id.Parking);
            Parking.setText(rs.getString(7));

        }
    }
}

From source file:com.mobshep.insufficienttls.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    referenceXML();//  w w  w .j  ava 2  s  .  c o  m

    logPrefSession();
    logProviderSession();

    if (checkSession()) {
        // Intent intent = new Intent(MainActivity.this, LoggedIn.class);
        // startActivity(intent);
    }

    //TODO
    //Remove this and replace with AsyncTask
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    //end remove

    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String address = SP.getString("server_preference", "NA");

    Toast addressTest = Toast.makeText(MainActivity.this, "Server Address : " + address, Toast.LENGTH_LONG);
    addressTest.show();

}

From source file:com.eusecom.attendance.MyDownloadService.java

@Override
public void onCreate() {
    super.onCreate();

    // Initialize Storage
    mStorage = FirebaseStorage.getInstance().getReference();
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
}

From source file:com.androiddevbook.onyourbike.chapter11.activities.BaseActivity.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private void setupStrictMode() {
    // Make sure we do nothing silly!
    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());

        StrictMode//from w  w w  .  java  2 s .c  o  m
                .setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().penaltyDeath().build());
    }
}

From source file:com.android.volley.misc.Utils.java

@TargetApi(11)
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();/*  w w  w  . j  av a2s . com*/
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:it.sineo.android.tileMapEditor.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (C.DEVELOPER_MODE) {
        StrictMode.setThreadPolicy(
                new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().penaltyDeathOnNetwork().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }/* w w  w .jav a 2  s .co m*/

    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    gvPreview = (GridView) findViewById(R.id.home_grid);
    /* Empty grid view */
    emptyGrid = getLayoutInflater().inflate(R.layout.home_grid_empty, null);
    emptyGrid.findViewById(R.id.home_grid_empty).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(C.DIALOG_NEW_MAP);
        }
    });
    @SuppressWarnings("deprecation")
    int emptyGrid_layout_size = LayoutParams.FILL_PARENT;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        emptyGrid_layout_size = LayoutParams.MATCH_PARENT;
    }
    addContentView(emptyGrid, new LayoutParams(emptyGrid_layout_size, emptyGrid_layout_size));
    gvPreview.setEmptyView(emptyGrid);

    /* Real grid view, with background loading */
    getSupportLoaderManager().initLoader(0, null, this);

    String[] cols = new String[] { "_id", "_name", "_json_data", "_last_update", };

    adapter = new MySimpleCursorAdapter(getApplicationContext(), R.layout.home_grid_item, null, cols, null, 0);

    gvPreview.setAdapter(adapter);
    gvPreview.setOnItemClickListener(this);

    /* Context menu */
    registerForContextMenu(gvPreview);

    // showDialog(C.DIALOG_LOADING_MAPS);
    progressDialog = ProgressDialog.show(HomeActivity.this, null, getString(R.string.home_dlg_loading_maps),
            true);
}

From source file:com.mobshep.shepherdlogin.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    referenceXML();/*  w  w  w.  jav  a2 s  .  co  m*/

    logPrefSession();
    logProviderSession();

    if (checkSession()) {
        Intent intent = new Intent(MainActivity.this, LoggedIn.class);
        startActivity(intent);
    }

    //TODO
    //Remove this and replace with AsyncTask
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    //end remove

    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String address = SP.getString("server_preference", "NA");

    Toast addressTest = Toast.makeText(MainActivity.this, "Server Address : " + address, Toast.LENGTH_LONG);
    addressTest.show();

}