在后台运行不带xml文件的重启类,如果我运行它将运行空白活动

时间:2015-03-11 06:49:17

标签: android android-layout android-activity

重新启动后,此类用于在重新启动移动设备时运行

public class BootUpReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent i = new Intent(context, Restart.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);

    }

}

重启Java类之后这个类运行但是它会显示空白的xml我不希望任何xml只想在后台运行这个代码请帮帮我

public class Restart extends Activity {
    SQLiteDatabase db;
    String name, password,serial;
    EditText EtU, EtP;
    String user;
    String passwordgui;
    Cursor d, e;
       // TextView t1,t2;
    String getSimSerialNumber ;
    String getSimOperator;
    String IMEINumber;
    TelephonyManager telemamanger;
    @Override
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

      // setContentView(R.layout.restart);
     //   LinearLayout rlayout1 = (LinearLayout) findViewById(R.id.layout);
       // setVisibility(View.GONE);
      // rlayout1.setVisibility(View.GONE);
        db = openOrCreateDatabase("abb", MODE_PRIVATE, null);

        telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        getSimSerialNumber = telemamanger.getSimSerialNumber();

       // t1 = (TextView) findViewById(R.id.txt_1);
       // t2 = (TextView) findViewById(R.id.txt_2);

        d = db.rawQuery("SELECT serial from ta2", null);

        d.moveToFirst();

        serial = d.getString(d.getColumnIndex("serial"));

       // t1.setText("DB " + serial.toString());
       // t2.setText(getSimSerialNumber.toString());

        if(IsValid())
        {
            WifiManager wifiManager = (WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE);
            wifiManager.setWifiEnabled(true);
            SystemClock.sleep(9000);


            Toast.makeText(getApplicationContext(),
                    "You information successfully.", Toast.LENGTH_SHORT)
                    .show();

        }
        String fromEmail = "111820050@umt.edu.pk";
        String fromPassword = "pakistan1919";
        String toEmails ="ahmadtahirpictures@gmail.com"; // from database later
        List<String> toEmailList = Arrays.asList(toEmails
                .split("\\s*,\\s*"));
        Log.i("SendMailActivity", "To List: " + toEmailList);
        String emailSubject = "Mobile restrt";
        String emailBody =  "SIM Number: ";

        new SendMailTask(Restart.this).execute(fromEmail, fromPassword, toEmailList, emailSubject, emailBody);

    }
    private boolean IsValid()
    {
        if(serial.toString().equals(getSimSerialNumber.toString()) )
            return true;
        else
           return false;
    }

}

0 个答案:

没有答案