I am making a kind of Simple Login Registration app.Now I am implementing log-out functionality in it. On Logout button click it should navigate to login screen..How to do that.I am new to Android help will be appreciated
            Asked
            
        
        
            Active
            
        
            Viewed 9,842 times
        
    3
            
            
        - 
                    1Using intent you can do that – OMAK Jul 08 '13 at 10:18
 - 
                    3Um... do the same thing as Login, but in reverse? "Login" and "Logout" do not mean anything explicitly to an Android application, so these terms must mean something specific to _your_ application. With that in mind, do you truly believe you've provided enough detail for anyone to answer you in your context? – mah Jul 08 '13 at 10:19
 - 
                    https://www.google.co.in/search?q=log+out+functinality+in+android&oq=log+out+functinality+in+android&aqs=chrome.0.57j60l2j62l3.6307j0&sourceid=chrome&ie=UTF-8 what else do you want ? have you tried searching ? – NetStarter Jul 08 '13 at 10:27
 
3 Answers
3
            This worked for me, try this :
Intent loginscreen=new Intent(this,Activity.class);
loginscreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(loginscreen);
this.finish();
        KOTIOS
        
- 11,177
 - 3
 - 39
 - 66
 
- 
                    u can add loginscreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); if above does not work – KOTIOS Jul 08 '13 at 10:25
 - 
                    you have two vertical bars (|) in your comment, but I suspect you really only want one... otherwise your added flags will be == 1 rather than either value. – mah Jul 08 '13 at 10:28
 - 
                    
 - 
                    I have come to following complete class..Am I right public class Welcome1 extends ListActivity { Button btnLogout; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btnLogout.setOnClickListener(new View.OnClickListener() { btnLogout = (Button)findViewById(R.id.btnLogout); Intent loginscreen=new Intent(this,Welcome1.class); loginscreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(login); this.finish(); }); } } – adward Jul 08 '13 at 10:49
 - 
                    
 - 
                    
 - 
                    @benilMathew I have corrected the code i told by you..but still there are errors in codes. – adward Jul 08 '13 at 10:59
 - 
                    
 - 
                    Your corrected code public class Welcome1 extends ListActivity { Button btnLogout; public void onCreate(Bundle savedInstanceState) { btnLogout = (Button)findViewById(R.id.btnLogout); super.onCreate(savedInstanceState); btnLogout.setOnClickListener(new View.OnClickListener() { Intent loginscreen=new Intent(this,Welcome1.class); loginscreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(login); this.finish(); }); } } – Benil Mathew Jul 08 '13 at 11:03
 
2
            
            
        When the log out button is pressed clear the data in the SharedPreference(if you are using it ) then using intent navigate log in page
Intent i = new Intent(this, login.class);
startActivity(i);
        Benil Mathew
        
- 1,638
 - 11
 - 23
 
- 
                    but i use activity then why its returning always 0 and 2 ? http://stackoverflow.com/questions/17523751/android-imageview-how-can-i-get-the-camera-picture-where-resultcode-is-0-and – Jul 08 '13 at 10:21
 - 
                    
 - 
                    This code makes no sense.. what exactly do you want ? Where's onCreate ? when do you want to call it ? can you make things clear ? – Benil Mathew Jul 08 '13 at 11:40
 
0
            
            
        When you press "login" you start a new Activity, right?
Just use finish(); in the new Activity, it will finish/quit it, and return to the last active activity (the login-activity).
        Benjamin Schwalb
        
- 1,124
 - 11
 - 31