मुझे लगता है कि जैसे प्रवेश, पंजीकरण, सत्र के रूप में उपयोगकर्ता प्रमाणीकरण के सबसे ख्याल रखता है, UserApp के लिए SDK बना लिया है hepls होगा, उपयोगकर्ता प्रोफाइल, सामाजिक लॉगिन, आदि
https://github.com/userapp-io/userapp-android
यह खुला स्रोत है, इसलिए आप इसे afte को संशोधित कर सकता है अपनी जरूरतों को पूरा करें और अपनी सेवाओं से जुड़ें।
लॉगिन प्रपत्र एक टुकड़ा है कि AuthFragment
फैली हुई है, इस तरह के भीतर रखा जाएगा: तब इसे जोड़ने
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Progress -->
<LinearLayout
android:id="@+id/login_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp" />
<TextView
android:id="@+id/login_status_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif-light"
android:text="@string/login_progress_signing_in"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<!-- Login form -->
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/username"
android:maxLines="1"
android:singleLine="true" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="@string/password"
android:maxLines="1"
android:singleLine="true" />
<Button
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:text="@string/login" />
<Button
android:id="@+id/facebook_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:text="@string/facebook_login" />
<Button
android:id="@+id/show_signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:text="@string/signup" />
<TextView
android:id="@+id/error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
</LinearLayout>
:
public class LoginFragment extends AuthFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_signup, container, false);
// Setup the login form with bindings to UserApp
super.setupLoginForm(view, R.id.login, R.id.password, R.id.login_button);
return view;
}
@Override
public Boolean onLoginStart(String login, String password, Boolean isSocialLogin) {
// Show loader when waiting for server
getView().findViewById(R.id.login_form).setVisibility(View.GONE);
getView().findViewById(R.id.login_status).setVisibility(View.VISIBLE);
// Return true to complete the login
return true;
}
@Override
public void onLoginCompleted(Boolean authenticated, Exception exception) {
// Hide the loader
getView().findViewById(R.id.login_form).setVisibility(View.VISIBLE);
getView().findViewById(R.id.login_status).setVisibility(View.GONE);
if (exception != null) {
// Show an error message
((TextView) getView().findViewById(R.id.error_text)).setText(exception.getMessage());
} else {
// Clear the message
((TextView) getView().findViewById(R.id.error_text)).setText("");
}
}
}
और LoginFragment
के लिए लेआउट कुछ इस तरह दिखेगा आपके मुख्य गतिविधि के लेआउट में, एक अन्य टुकड़े के साथ जिसमें आपका "डैशबोर्ड" होता है:
<RelativeLayout ... >
<fragment
android:id="@+id/loginFragment"
android:name="com.example.demo.LoginFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
...
</RelativeLayout>
यह अभी संक्षेप में दिखाया गया है कि लाइब्रेरी का उपयोग कैसे किया जा सकता है। इसका उपयोग कैसे करें इसके बारे में अधिक जानकारी के लिए प्रलेखन देखें। गिटहब पर डेमो ऐप पर भी नज़र डालें।
स्वीकृत उत्तर में उल्लिखित अनुसार; उपयोगकर्ता जब एप्लिकेशन बंद हो लॉग आउट करने के लिए, अपने मुख्य गतिविधि में onStop()
घटना पर सुनने और session.logout()
कहते हैं, इस तरह:
UserApp.Session session;
session.logout();
केवल एक चीज मेरा मतलब है कि लॉगिन वर्ग को एक अलग फ़ाइल के रूप में लिखा जाना चाहिए –
एंड्रॉइड एपीआई का पूरा विचार विभिन्न विचारों को अलग-अलग गतिविधियों में अलग करना है। तो आपके लिए ऐप के लिए आप शायद लॉग इन स्क्रीन को एक वर्ग (गतिविधि वर्ग को विस्तारित करना) और अपनी मुख्य स्क्रीन को एक और वर्ग (गतिविधि वर्ग को विस्तारित करना) के रूप में चाहते हैं। जब लॉगिन सफल होता है तो आप डेवलपर लाइफ ट्यूटोरियल में समझाए गए स्टार्टएक्टिविटी() या startActivityForResult() का उपयोग करके अपनी लॉगिन गतिविधि से अपनी मुख्य गतिविधि को फायर कर देते हैं। –