android.view.InflateException:二进制XML文件行#28:膨胀类片段时出错
我正在尝试开发一个应用程序,它有一个导航抽屉和一个片段来显示数据。这是我的应用程序活动堆栈: ->登录(检查是否已登录,它将跳过加载视图并进入时间线) ->时间线 这是我获取错误的方式: ->我启动应用程序 ->它绕过登录屏幕,因为我已经登录了 ->一切正常,然后我从菜单抽屉中单击“注销”或按“上一步”按钮 ->我回到登录屏幕 ->现在,如果我再次按Login并再次启动时间线活动,我的应用程序将崩溃… 这是密码。这是logcat:android.view.InflateException:二进制XML文件行#28:膨胀类片段时出错,android,android-fragments,nullpointerexception,inflate-exception,Android,Android Fragments,Nullpointerexception,Inflate Exception,我正在尝试开发一个应用程序,它有一个导航抽屉和一个片段来显示数据。这是我的应用程序活动堆栈: ->登录(检查是否已登录,它将跳过加载视图并进入时间线) ->时间线 这是我获取错误的方式: ->我启动应用程序 ->它绕过登录屏幕,因为我已经登录了 ->一切正常,然后我从菜单抽屉中单击“注销”或按“上一步”按钮 ->我回到登录屏幕 ->现在,如果我再次按Login并再次启动时间线活动,我的应用程序将崩溃… 这是密码。这是logcat: 11-15 21:11:52.050 18695-18695/
11-15 21:11:52.050 18695-18695/lazarko.pocketformulas E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{lazarko.pocketformulas/lazarko.pocketformulas.Timeline}: android.view.InflateException: Binary XML file line #28: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5520)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:324)
at android.app.Activity.setContentView(Activity.java:1912)
at lazarko.pocketformulas.Timeline.onCreate(Timeline.java:35)
at android.app.Activity.performCreate(Activity.java:5066)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5520)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:1097)
at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1306)
at lazarko.pocketformulas.NavigationDrawerFragment.selectItem(NavigationDrawerFragment.java:209)
at lazarko.pocketformulas.NavigationDrawerFragment.onCreate(NavigationDrawerFragment.java:82)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:798)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1015)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1114)
at android.app.Activity.onCreateView(Activity.java:4722)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:324)
at android.app.Activity.setContentView(Activity.java:1912)
at lazarko.pocketformulas.Timeline.onCreate(Timeline.java:35)
at android.app.Activity.performCreate(Activity.java:5066)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5520)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
at dalvik.system.NativeStart.main(Native Method)
这是我的活动代码:
public class Timeline extends FragmentActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks, SearchView.OnQueryTextListener {
private static NavigationDrawerFragment mNavigationDrawerFragment;
private CharSequence mTitle;
public static Context context;
SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timeline);
context = getApplicationContext();
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
public static Context getContext() {
return context;
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onResume() {
super.onStart();
FragmentManager fragmentManager = getSupportFragmentManager();
SharedPreferences preferencesFragmentData = getSharedPreferences("fragmentData", 0);
String fragmentID = preferencesFragmentData.getString("currentFragment", "");
if(fragmentID == "FAVORITES_FRAGMENT")
fragmentManager.beginTransaction().replace(R.id.container, new Favorites()).commit();
else if (fragmentID == "TIMELINE_FRAGMENT")
fragmentManager.beginTransaction().replace(R.id.container, new PlaceholderFragment()).commit();
else if (fragmentID == "SETTINGS_FRAGMENT")
fragmentManager.beginTransaction().replace(R.id.container, new Settings()).commit();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
public void onNavigationDrawerItemSelected(int position) {
FragmentManager fragmentManager = getSupportFragmentManager();
SharedPreferences preferencesFragmentData = getSharedPreferences("fragmentData", 0);
SharedPreferences.Editor editorFragmentData = preferencesFragmentData.edit();
switch(position) {
case 1:
//Timeline clicked
editorFragmentData.putString("currentFragment", "TIMELINE_FRAGMENT");
editorFragmentData.commit();
fragmentManager.beginTransaction()
.replace(R.id.container, new PlaceholderFragment(), "TIMELINE_FRAGMENT")
.commit();
break;
case 2:
//Favorites clicked
editorFragmentData.putString("currentFragment", "FAVORITES_FRAGMENT");
editorFragmentData.commit();
fragmentManager.beginTransaction()
.replace(R.id.container, new Favorites(), "FAVORITES_FRAGMENT")
.commit();
break;
case 3:
//Settings clicked
editorFragmentData.putString("currentFragment", "SETTINGS_FRAGMENT");
editorFragmentData.commit();
fragmentManager.beginTransaction()
.replace(R.id.container, new Settings())
.commit();
break;
case 4:
//Log Out clicked
SharedPreferences loginDataPreferences = getSharedPreferences("loginData", 0);
SharedPreferences.Editor editorLogin = loginDataPreferences.edit();
editorLogin.putBoolean("loggedIn", false);
editorLogin.commit();
Intent intent = new Intent(getApplicationContext(), Login.class);
startActivity(intent);
break;
default:
editorFragmentData.putString("currentFragment", "TIMELINE_FRAGMENT");
editorFragmentData.commit();
fragmentManager.beginTransaction()
.replace(R.id.container, new PlaceholderFragment())
.commit();
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if(!mNavigationDrawerFragment.isDrawerOpen()) {
menu.clear();
getMenuInflater().inflate(R.menu.timeline, menu);
//restoreActionBar();
searchView = new SearchView(getActionBar().getThemedContext());
searchView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
searchView.setQueryHint(Html.fromHtml("<font color=#FFFFFF>Search ... </font>"));
searchView.setOnQueryTextListener(this);
searchView.clearFocus();
menu.add("Search").setIcon(R.drawable.ic_action_action_search).setActionView(searchView).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
return false;
}
//User searched for a formula and pressed Enter
@Override
public boolean onQueryTextSubmit(String s) {
SharedPreferences preferencesFragmentData = getSharedPreferences("fragmentData", 0);
String currentFragment = preferencesFragmentData.getString("currentFragment", "");
if(currentFragment == "TIMELINE_FRAGMENT"){
//Log.e("TIMELINE", currentFragment + "IN THE IF FRAGMENT");
//Toast.makeText(getContext(), "You searched for: " + s + " in Timeline Fragment!", Toast.LENGTH_SHORT).show();
} else if (currentFragment == "FAVORITES_FRAGMENT"){
//Log.e("TIMELINE", currentFragment + "IN THE IF FRAGMENT");
//Toast.makeText(getContext(), "You searched for: " + s + " in FAVORITES Fragment!", Toast.LENGTH_SHORT).show();
}
//Hide the keyboard
InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
invalidateOptionsMenu();
return true;
}
//user started typing, this code block is for Autocomplete or Suggestions based on his current input
@Override
public boolean onQueryTextChange(String s) {
return false;
}
}
以下是我的activity_timeline.xml文件,其中出现错误:
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".Timeline">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/svContainerViews">
<LinearLayout android:id="@+id/llScrollViewContainerItems" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent"
android:layout_gravity="start"
android:name="lazarko.pocketformulas.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
和我的登录活动类:
/**
* Created by lazarnikolov on 11/8/14.
*/
public class Login extends Activity{
EditText etEmail, etPassword;
Button bLogin, bRegister;
Typeface font;
TextView tvLogIn;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences preferences = getSharedPreferences("loginData", 0);
boolean loggedIn = preferences.getBoolean("loggedIn", false);
if(loggedIn) {
Intent intent = new Intent("android.intent.action.TIMELINE");
startActivity(intent);
}
SharedPreferences initialFragmentData = getSharedPreferences("fragmentData", 0);
SharedPreferences.Editor initialEditorFragmentData = initialFragmentData.edit();
initialEditorFragmentData.putString("currentFragment", "TIMELINE_FRAGMENT");
initialEditorFragmentData.commit();
setContentView(R.layout.login);
font = Typeface.createFromAsset(getAssets(), "ubuntu.ttf");
etEmail = (EditText) findViewById(R.id.etEmail);
etEmail.setTypeface(font);
etPassword = (EditText) findViewById(R.id.etPassword);
etPassword.setTypeface(font);
tvLogIn = (TextView) findViewById(R.id.tvRegister);
tvLogIn.setTypeface(font);
bLogin = (Button) findViewById(R.id.bLogin);
bLogin.setTypeface(font);
bLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences preferences = getSharedPreferences("loginData", 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("loggedIn", true);
editor.commit();
communicate();
Intent intent = new Intent("android.intent.action.TIMELINE");
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
bRegister = (Button) findViewById(R.id.bRegister);
bRegister.setTypeface(font);
bRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.REGISTER");
startActivity(intent);
}
});
}
// SERVER COMMUNICATION CLASS INITIALIZATION
private void communicate() {
new GetData().execute();
}
// SERVER COMMUNICATION CLASS
private class GetData extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... voids) {
Looper.prepare();
String data = "";
InputStream inputStream = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("*******");
String json = "";
JSONObject object = new JSONObject();
object.accumulate("email", etEmail.getText().toString());
object.accumulate("password", etPassword.getText().toString());
json = object.toString();
StringEntity se = new StringEntity(json);
httpPost.setEntity(se);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(httpPost);
inputStream = response.getEntity().getContent();
if(inputStream != null){
Toast.makeText(getApplicationContext(), "Logged in!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Invalid username/password", Toast.LENGTH_SHORT).show();
}
} catch(Exception e) {
Log.e("log_tag", "Error in http connection: " + e.toString());
}
return data;
}
@Override
protected void onPostExecute(String result) {
//Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
}
}
@Override onStart(), onRestart(), onResume()...
}
/**
*拉扎尔尼科洛夫于2014年11月8日创作。
*/
公共类登录扩展活动{
编辑文本etEmail,etPassword;
Button bLogin,bRegister;
字体;
文本视图登录;
@凌驾
创建时受保护的void(最终捆绑包savedInstanceState){
super.onCreate(savedInstanceState);
SharedReferences首选项=GetSharedReferences(“登录数据”,0);
boolean loggedIn=preferences.getBoolean(“loggedIn”,false);
if(loggedIn){
意向=新意向(“android.Intent.action.TIMELINE”);
星触觉(意向);
}
SharedReferences initialFragmentData=GetSharedReferences(“fragmentData”,0);
SharedReferences.Editor initialEditorFragmentData=initialFragmentData.edit();
putString(“currentFragment”、“TIMELINE_FRAGMENT”);
initialEditorFragmentData.commit();
setContentView(R.layout.login);
font=Typeface.createFromAsset(getAssets(),“ubuntu.ttf”);
etEmail=(EditText)findViewById(R.id.etEmail);
etEmail.setTypeface(字体);
etPassword=(EditText)findViewById(R.id.etPassword);
etPassword.setTypeface(字体);
tvLogIn=(TextView)findViewById(R.id.tvRegister);
tvLogIn.setTypeface(字体);
bLogin=(按钮)findviewbyd(R.id.bLogin);
bLogin.setTypeface(字体);
bLogin.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
SharedReferences首选项=GetSharedReferences(“登录数据”,0);
SharedReferences.Editor=首选项.edit();
编辑器.putBoolean(“loggedIn”,true);
commit();
沟通();
意向=新意向(“android.Intent.action.TIMELINE”);
//intent.setFlags(intent.FLAG\u活动\u新任务);
intent.setFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
星触觉(意向);
}
});
b注册表=(按钮)findViewById(R.id.b注册表);
b.设置字体(字体);
bRegister.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
意向=新意向(“android.Intent.action.REGISTER”);
星触觉(意向);
}
});
}
//服务器通信类初始化
私人通讯{
新建GetData().execute();
}
//服务器通信类
私有类GetData扩展异步任务{
@凌驾
受保护的字符串背景(无效…无效){
Looper.prepare();
字符串数据=”;
InputStream InputStream=null;
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“*******”);
字符串json=“”;
JSONObject对象=新的JSONObject();
累积(“email”,etEmail.getText().toString());
object.acculate(“password”,etPassword.getText().toString());
json=object.toString();
StringEntity se=新的StringEntity(json);
httpPost.setEntity(se);
setHeader(“接受”、“应用程序/json”);
setHeader(“内容类型”、“应用程序/json”);
HttpResponse response=httpClient.execute(httpPost);
inputStream=response.getEntity().getContent();
如果(inputStream!=null){
Toast.makeText(getApplicationContext(),“登录!”,Toast.LENGTH\u SHORT.show();
}否则{
Toast.makeText(getApplicationContext(),“无效用户名/密码”,Toast.LENGTH_SHORT.show();
}
}捕获(例外e){
e(“Log_标记”,“http连接错误:”+e.toString());
}
返回数据;
}
@凌驾
受保护的void onPostExecute(字符串结果){
//Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG.show();
}
}
@重写onStart()、onRestart()、onResume()。。。
}
我已经找了很久了,但仍然找不到解决办法。请看一看,然后告诉我你认为是什么问题
非常感谢 仔细查看/debug
lazarko.pocketformals.NavigationDrawerFragment.java
第209行(它属于selectItem()
method)根据堆栈跟踪,可能存在
null
或未正确初始化的对象Update
要想弄清楚为什么有时会发生,有时不会发生(如果我理解正确的话),还有更多的问题要问
/**
* Created by lazarnikolov on 11/8/14.
*/
public class Login extends Activity{
EditText etEmail, etPassword;
Button bLogin, bRegister;
Typeface font;
TextView tvLogIn;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences preferences = getSharedPreferences("loginData", 0);
boolean loggedIn = preferences.getBoolean("loggedIn", false);
if(loggedIn) {
Intent intent = new Intent("android.intent.action.TIMELINE");
startActivity(intent);
}
SharedPreferences initialFragmentData = getSharedPreferences("fragmentData", 0);
SharedPreferences.Editor initialEditorFragmentData = initialFragmentData.edit();
initialEditorFragmentData.putString("currentFragment", "TIMELINE_FRAGMENT");
initialEditorFragmentData.commit();
setContentView(R.layout.login);
font = Typeface.createFromAsset(getAssets(), "ubuntu.ttf");
etEmail = (EditText) findViewById(R.id.etEmail);
etEmail.setTypeface(font);
etPassword = (EditText) findViewById(R.id.etPassword);
etPassword.setTypeface(font);
tvLogIn = (TextView) findViewById(R.id.tvRegister);
tvLogIn.setTypeface(font);
bLogin = (Button) findViewById(R.id.bLogin);
bLogin.setTypeface(font);
bLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences preferences = getSharedPreferences("loginData", 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("loggedIn", true);
editor.commit();
communicate();
Intent intent = new Intent("android.intent.action.TIMELINE");
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
bRegister = (Button) findViewById(R.id.bRegister);
bRegister.setTypeface(font);
bRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent("android.intent.action.REGISTER");
startActivity(intent);
}
});
}
// SERVER COMMUNICATION CLASS INITIALIZATION
private void communicate() {
new GetData().execute();
}
// SERVER COMMUNICATION CLASS
private class GetData extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... voids) {
Looper.prepare();
String data = "";
InputStream inputStream = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("*******");
String json = "";
JSONObject object = new JSONObject();
object.accumulate("email", etEmail.getText().toString());
object.accumulate("password", etPassword.getText().toString());
json = object.toString();
StringEntity se = new StringEntity(json);
httpPost.setEntity(se);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(httpPost);
inputStream = response.getEntity().getContent();
if(inputStream != null){
Toast.makeText(getApplicationContext(), "Logged in!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Invalid username/password", Toast.LENGTH_SHORT).show();
}
} catch(Exception e) {
Log.e("log_tag", "Error in http connection: " + e.toString());
}
return data;
}
@Override
protected void onPostExecute(String result) {
//Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
}
}
@Override onStart(), onRestart(), onResume()...
}
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);