【发布时间】:2014-11-15 11:11:23
【问题描述】:
我有一个自定义操作栏和附加在后台运行的 onclick,由于某种奇怪的原因,我的应用程序强制关闭。
我正在 doinbackground 中进行网络操作
下面附上代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.enroll);
final ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(enroll.this);
final View mCustomView = mInflater.inflate(R.layout.custom_actionbar_enroll, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text1);
mTitleTextView.setText("True Tracer");
String fontPath = "fonts/stasmic_.ttf";
Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
mTitleTextView.setTypeface(tf);
final ImageButton imageButton = (ImageButton) mCustomView
.findViewById(R.id.imageButton1);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
tpass=(TextView)findViewById(R.id.tip);
otp1=(EditText)findViewById(R.id.otp1);
pref = getApplicationContext().getSharedPreferences("MyPref", 0);
String samp=pref.getString("mynumber", null);
tpass.setText("Self authentication SMS sent \n with activation code to "+samp);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
backend runner = new backend();
runner.execute();
}
});
}
class backend extends AsyncTask<String, Void, Result>
{
@Override
protected Result doInBackground(String... params) {
do something();
}
}
【问题讨论】:
-
发布您的 logcat 错误
-
你有没有在清单文件中提到网络权限?
-
正在我的手机上运行它..不确定如何获取 logcat
标签: android android-asynctask action