java - i want to move from one activity to the other help me i am new user? -


this manifest file

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.virasatsolutions.www.donapp">      <!-- auto-complete email text field in login form user's emails -->      <uses-permission android:name="android.permission.get_accounts" />     <uses-permission android:name="android.permission.read_profile" />     <uses-permission android:name="android.permission.read_contacts" />      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme" >       <activity         android:name=".loginactivity"         android:label="@string/app_name">         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <activity         android:name=".mainactivity"         android:label="@string/title_activity_main">          <intent-filter>             <action android:name="android.intent.action.mainactivity" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <activity         android:name=".donation"         android:label="@string/title_activity_donation"         android:theme="@style/apptheme.noactionbar" />         <activity android:name=".sign_up"             android:label="@string/title_sign_up">             <intent-filter>                 <action android:name="android.intent.action.sign_up" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>           </application>  </manifest> 

// layout want move after login code login activity dummy login

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     app:layout_behavior="@string/appbar_scrolling_view_behavior"     tools:context=".mainactivity"     tools:showin="@layout/activity_main"     android:background="#1f874e"    >         <tabhost         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/tabhost"         android:layout_weight="1">          <linearlayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:orientation="vertical">              <tabwidget                 android:id="@android:id/tabs"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_margintop="-20dp">              </tabwidget>              <framelayout                 android:id="@android:id/tabcontent"                 android:layout_width="match_parent"                 android:layout_height="match_parent">                  <relativelayout                     android:id="@+id/donate"                     android:layout_width="match_parent"                     android:layout_height="match_parent"                     android:orientation="vertical"                     android:clickable="true"                     android:fadingedge="horizontal"                     >                       <radiogroup                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignparentstart="true"                         android:layout_alignparentleft="true"                         android:id="@+id/dongroup"                         android:layout_margintop="20dp">                           <radiobutton                             android:layout_width="wrap_content"                             android:layout_height="wrap_content"                             android:text="@string/school"                             android:id="@+id/radiobutton4"                             android:layout_gravity="center_vertical"                             android:layout_weight="1"                             />                           <radiobutton                             android:layout_width="wrap_content"                             android:layout_height="wrap_content"                             android:text="@string/college"                             android:id="@+id/radiobutton3"                             android:layout_gravity="center_vertical"                             android:layout_weight="1" />                          <radiobutton                             android:layout_width="wrap_content"                             android:layout_height="wrap_content"                             android:text="@string/ngo"                             android:id="@+id/radiobutton2"                             android:layout_gravity="center_vertical"                             android:layout_weight="1" />                          <radiobutton                             android:layout_width="wrap_content"                             android:layout_height="wrap_content"                             android:text="@string/university"                             android:id="@+id/radiobutton"                             android:layout_gravity="center_vertical"                             android:layout_weight="1" />                        </radiogroup>                     <spinner                         android:layout_width="match_parent"                         android:layout_height="wrap_content"                         android:id="@+id/spinner"                         android:layout_gravity="center_horizontal"                         android:layout_weight="1"                         android:layout_alignparentend="true"                         android:layout_alignparentright="true"                         android:layout_toendof="@+id/dongroup"                         android:layout_torightof="@+id/dongroup"                         android:layout_margintop="25dp">                       </spinner>                    </relativelayout>                    <relativelayout                     android:id="@+id/donation_history"                     android:layout_width="match_parent"                     android:layout_height="match_parent"                     android:orientation="vertical"                     android:text="@string/donation_history">                    </relativelayout>             </framelayout>         </linearlayout>     </tabhost>  </linearlayout> 

this loginactivity layout

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="center_horizontal"     android:orientation="vertical"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="com.virasatsolutions.www.donapp.loginactivity"     android:background="#1f874e" >      <!-- login progress -->     <progressbar         android:id="@+id/login_progress"         style="?android:attr/progressbarstylelarge"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginbottom="8dp"         android:visibility="gone" />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancelarge"         android:text="login"         android:id="@+id/textview5"         android:layout_marginleft="-100dp"         android:textsize="50dp"/>      <scrollview         android:id="@+id/login_form"         android:layout_width="match_parent"         android:layout_height="match_parent">          <linearlayout             android:id="@+id/email_login_form"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="vertical"             android:background="#72ce82"             android:layout_margintop="100dp">              <android.support.design.widget.textinputlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content">                  <autocompletetextview                     android:id="@+id/email"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:hint="@string/prompt_email"                     android:inputtype="textemailaddress"                     android:maxlines="1"                     android:singleline="true" />              </android.support.design.widget.textinputlayout>              <android.support.design.widget.textinputlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content">                  <edittext                     android:id="@+id/password"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:hint="@string/prompt_password"                     android:imeactionid="@+id/login"                     android:imeactionlabel="@string/action_sign_in_short"                     android:imeoptions="actionunspecified"                     android:inputtype="textpassword"                     android:maxlines="1"                     android:singleline="true" />              </android.support.design.widget.textinputlayout>              <button                 android:id="@+id/email_sign_in_button"                 style="?android:textappearancesmall"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_margintop="16dp"                 android:text="@string/action_sign_in"                 android:textstyle="bold"                 android:onclick="main"/>              <button                 style="?android:attr/buttonstylesmall"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="sign up"                 android:id="@+id/button2"                 android:layout_gravity="center_horizontal"                 android:onclick="signup"/>           </linearlayout>     </scrollview> </linearlayout>            // loginactivity...      import android.animation.animator;     import android.animation.animatorlisteneradapter; import android.annotation.targetapi; import android.content.intent; import android.content.pm.packagemanager; import android.support.annotation.nonnull; import android.support.design.widget.snackbar; import android.support.v7.app.appcompatactivity; import android.app.loadermanager.loadercallbacks;  import android.content.cursorloader; import android.content.loader; import android.database.cursor; import android.net.uri; import android.os.asynctask;  import android.os.build; import android.os.bundle; import android.provider.contactscontract; import android.text.textutils; import android.util.log; import android.view.keyevent; import android.view.view; import android.view.view.onclicklistener; import android.view.inputmethod.editorinfo; import android.widget.arrayadapter; import android.widget.autocompletetextview; import android.widget.button; import android.widget.edittext; import android.widget.textview;  import java.util.arraylist; import java.util.list;  import static android.manifest.permission.read_contacts;  /**  * login screen offers login via email/password.  */       public class loginactivity extends appcompatactivity implements loadercallbacks<cursor> {      /**      * id identity read_contacts permission request.      */     private static final int request_read_contacts = 0;      /**      * dummy authentication store containing known user names , passwords.      * todo: remove after connecting real authentication system.      */     private static final string[] dummy_credentials = new string[]{             "foo@example.com:hello", "bar@example.com:world"     };     /**      * keep track of login task ensure can cancel if requested.      */     private userlogintask mauthtask = null;      // ui references.     private autocompletetextview memailview;     private edittext mpasswordview;     private view mprogressview;     private view mloginformview;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_login);           // set login form.         memailview = (autocompletetextview) findviewbyid(r.id.email);         populateautocomplete();          mpasswordview = (edittext) findviewbyid(r.id.password);         mpasswordview.setoneditoractionlistener(new textview.oneditoractionlistener() {             @override             public boolean oneditoraction(textview textview, int id, keyevent keyevent) {                 if (id == r.id.login || id == editorinfo.ime_null) {                     attemptlogin();                       return true;                  }                 return false;             }         });           button memailsigninbutton = (button) findviewbyid(r.id.email_sign_in_button);         memailsigninbutton.setonclicklistener(new onclicklistener() {             @override             public void onclick(view view) {                  setcontentview(r.layout.activity_main);                  final button button = (button) findviewbyid(r.id.email_sign_in_button);                 button.setonclicklistener(new view.onclicklistener() {                     public void onclick(view v) {                         // perform action on click                         main();                     }                  });             }         });          mloginformview = findviewbyid(r.id.login_form);         mprogressview = findviewbyid(r.id.login_progress);      }        private void populateautocomplete() {         if (!mayrequestcontacts()) {             return;         }          getloadermanager().initloader(0, null, this);     }      private boolean mayrequestcontacts() {         if (build.version.sdk_int < build.version_codes.m) {             return true;         }         if (checkselfpermission(read_contacts) == packagemanager.permission_granted) {             return true;         }         if (shouldshowrequestpermissionrationale(read_contacts)) {             snackbar.make(memailview, r.string.permission_rationale, snackbar.length_indefinite)                     .setaction(android.r.string.ok, new view.onclicklistener() {                         @override                         @targetapi(build.version_codes.m)                         public void onclick(view v) {                             requestpermissions(new string[]{read_contacts}, request_read_contacts);                         }                     });         } else {             requestpermissions(new string[]{read_contacts}, request_read_contacts);         }         return false;     }      /**      * callback received when permissions request has been completed.      */     @override     public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions,                                            @nonnull int[] grantresults) {         if (requestcode == request_read_contacts) {             if (grantresults.length == 1 && grantresults[0] == packagemanager.permission_granted) {                 populateautocomplete();             }         }     }       /**      * attempts sign in or register account specified login form.      * if there form errors (invalid email, missing fields, etc.),      * errors presented , no actual login attempt made.      */     private void attemptlogin() {         if (mauthtask != null) {             log.e("login task","login successfull");             return;         }             // reset errors.         memailview.seterror(null);         mpasswordview.seterror(null);          // store values @ time of login attempt.         string email = memailview.gettext().tostring();         string password = mpasswordview.gettext().tostring();          boolean cancel = false;         view focusview = null;          // check valid password, if user entered one.         if (!textutils.isempty(password) && !ispasswordvalid(password)) {             mpasswordview.seterror(getstring(r.string.error_invalid_password));             focusview = mpasswordview;             cancel = true;         }          // check valid email address.         if (textutils.isempty(email)) {             memailview.seterror(getstring(r.string.error_field_required));             focusview = memailview;             cancel = true;         } else if (!isemailvalid(email)) {             memailview.seterror(getstring(r.string.error_invalid_email));             focusview = memailview;             cancel = true;         }          if (cancel) { 

// there error; don't attempt login , focus first // form field error. focusview.requestfocus(); } else { // show progress spinner, , kick off background task // perform user login attempt. showprogress(true); mauthtask = new userlogintask(email, password); mauthtask.execute((void) null); } }

// code want run

    protected void main()     {         intent = new intent("android.intent.action.mainactivity");         startactivity(i);     }     protected void sign_up(view view)     {         if(view.getid()==r.id.button2)         {             intent = new intent("android.intent.action.sign_up");             startactivity(i);         }      }      private boolean isemailvalid(string email) { 

//todo: replace own logic return email.contains("@"); }

    private boolean ispasswordvalid(string password) { 

//todo: replace own logic return password.length() > 4; }

    /**      * shows progress ui , hides login form.      */     @targetapi(build.version_codes.honeycomb_mr2)     private void showprogress(final boolean show) { // on honeycomb mr2 have viewpropertyanimator apis, allow         // easy animations. if available, use these apis fade-in         // progress spinner.         if (build.version.sdk_int >= build.version_codes.honeycomb_mr2) {             int shortanimtime = getresources().getinteger(android.r.integer.config_shortanimtime);              mloginformview.setvisibility(show ? view.gone : view.visible);             mloginformview.animate().setduration(shortanimtime).alpha(                     show ? 0 : 1).setlistener(new animatorlisteneradapter() {                 @override                 public void onanimationend(animator animation) {                     mloginformview.setvisibility(show ? view.gone : view.visible);                 }             });              mprogressview.setvisibility(show ? view.visible : view.gone);             mprogressview.animate().setduration(shortanimtime).alpha(                     show ? 1 : 0).setlistener(new animatorlisteneradapter() {                 @override                 public void onanimationend(animator animation) {                     mprogressview.setvisibility(show ? view.visible : view.gone);                 }             });         } else { 

// viewpropertyanimator apis not available, show // , hide relevant ui components. mprogressview.setvisibility(show ? view.visible : view.gone); mloginformview.setvisibility(show ? view.gone : view.visible); } }

    @override     public loader<cursor> oncreateloader(int i, bundle bundle) {         return new cursorloader(this,                 // retrieve data rows device user's 'profile' contact.                 uri.withappendedpath(contactscontract.profile.content_uri,                         contactscontract.contacts.data.content_directory), profilequery.projection,                  // select email addresses.                 contactscontract.contacts.data.mimetype +                         " = ?", new string[]{contactscontract.commondatakinds.email                 .content_item_type}, 

// show primary email addresses first. note there won't // primary email address if user hasn't specified one. contactscontract.contacts.data.is_primary + " desc"); }

    @override     public void onloadfinished(loader<cursor> cursorloader, cursor cursor) {         list<string> emails = new arraylist<>();         cursor.movetofirst();         while (!cursor.isafterlast()) {             emails.add(cursor.getstring(profilequery.address));             cursor.movetonext();         }          addemailstoautocomplete(emails);     }      @override     public void onloaderreset(loader<cursor> cursorloader) {      }      private void addemailstoautocomplete(list<string> emailaddresscollection) { 

//create adapter tell autocompletetextview show in dropdown list. arrayadapter adapter = new arrayadapter<>(loginactivity.this, android.r.layout.simple_dropdown_item_1line, emailaddresscollection);

        memailview.setadapter(adapter);     }       private interface profilequery {         string[] projection = {                 contactscontract.commondatakinds.email.address,                 contactscontract.commondatakinds.email.is_primary,         };          int address = 0;         int is_primary = 1;     }      /**      * represents asynchronous login/registration task used authenticate      * user.      */     public class userlogintask extends asynctask<void, void, boolean> {          private final string memail;         private final string mpassword;          userlogintask(string email, string password) {             memail = email;             mpassword = password;         }          @override         protected boolean doinbackground(void... params) {             // todo: attempt authentication against network service.              try {                 // simulate network access.                 thread.sleep(2000);             } catch (interruptedexception e) {                 return false;             }              (string credential : dummy_credentials) {                 string[] pieces = credential.split(":");                 if (pieces[0].equals(memail)) {                     // account exists, return true if password matches.                     return pieces[1].equals(mpassword);                 }             }              // todo: register new account here.             return true;         }          @override         protected void onpostexecute(final boolean success) {             mauthtask = null;             showprogress(false);              if (success) {                 finish();             } else {                 mpasswordview.seterror(getstring(r.string.error_incorrect_password));                 mpasswordview.requestfocus();             }         }          @override         protected void oncancelled() {             mauthtask = null;             showprogress(false);         }       } } 

here reason of problem:

protected void main(){     intent = new intent("android.intent.action.mainactivity");     startactivity(i); } protected void sign_up(view view){ if(view.getid()==r.id.button2){     intent = new intent("android.intent.action.sign_up");     startactivity(i); } } 

but right way is:

intent myintent = new intent(currentactivity.this, nextactivity.class); myintent.putextra("key", value); //optional parameters currentactivity.this.startactivity(myintent); 

the android developer web key more information it.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -