Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7736409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:43:26+00:00 2026-06-01T07:43:26+00:00

I have created an activity called viewActivity. It displays the shared files and folders

  • 0

I have created an activity called viewActivity. It displays the shared files and folders in windows system. I am using the function listFiles() from jcifs.smb package. Initially the shared drives are displayed. I have made an option to call the listFiles() function recursively. That is when I click a particular folder in a drive, the contents of the file are displayed. When I once again click the folder which is inside the previous folder, its content are also displayed. The problem here is when I press the back button in android, it calls the previous activity instead of going back to previous folder. So how to achieve this functionality?

 //my package
package com.android.accesspc;

import java.net.MalformedURLException;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;

public class viewActivity extends Activity{

int id=0;
SmbFile previous=null;
int count=0;
void list(SmbFile obj)
{
    ScrollView sv = new ScrollView(this);
    LinearLayout layout=new LinearLayout(this);
    layout.setOrientation(0x00000001);
    try
    {
        SmbFile a[]=obj.listFiles();
        for(final SmbFile m:a)
        {
            if(!m.isHidden())
            {
                Button btn = new Button(this); 
                btn.setId(id); 
                if(m.isDirectory())
                {
                    btn.setText(m.getName().replace("/","")); 
                    btn.setTextSize((float)20);
                    btn.setOnClickListener(new 
                    View.OnClickListener()
                    {
                        public void onClick(View v) 
                        {
                previous=m;//used to hold previous smb object
                count++;//takes count of no of folders pressed 
                            list(m);
                        }
                    });
                }
                else
                {
                    btn.setText(m.getName()); 
                }
                layout.addView(btn);
                id++;
            }
        }
        sv.addView(layout);
        setContentView(sv);
    }
    catch(SmbException e)
    {
Toast displayMsg=Toast.makeText(this,"cannot list files",Toast.LENGTH_SHORT);
        displayMsg.show();
    }
}

String ip,name,password;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view);

    ip="192.168.0.100";//my ip address
    name="abc";//my windows username
    password="abcd";//my windows password

    SmbFile dir=null;
    String url= "smb://" + ip + "/";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, name, password);
    try 
    {
        dir = new SmbFile(url, auth);
    } 
    catch (MalformedURLException e1) 
    {
    Toast displayMsg=Toast.makeText(this,"Network error",Toast.LENGTH_SHORT);
        displayMsg.show();
    }
    //used to list files and folders of smb object initially
    list(dir);
}

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    if(!(count==0))
    {
        //if count is not 0,that means the user has clicked a folder
    //we have "previous" holding previous smb value which  has to be called now
        list(previous);
    }
    else
    {
        //the default behaviour
        super.onBackPressed();
    }
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:43:27+00:00Added an answer on June 1, 2026 at 7:43 am

    Override the super.onBackPressed()

     @Override
     public boolean onBackPressed(){
    
     //your code
     }
    

    Should work on 2.3.3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom workflow activity that copies attachments from a case to
I have created a web user control called Activity. I have defined a public-facing
I have created a function that updates some values from a database that I
I have created an activity which sends a number of notifications to status bar.
I have created an activity implementing on touch listener and onclick listener . Both
I am trying to display ListView . I have created one activity , in
i have created a workflow activity that do give the item creater of a
I have an application and every new created activity will start an async task
So I've created an Activity subclass called CustomTitlebarActivity. Essentially, each main activity in my
I have created a user called wine to run Wine under for two reasons:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.