Page stops loading and then posts back to previous page

Hi there guys, i hope you all had a merry festive season, ok so now for my problem
I have a mobile app that is not that small, and i have been struggling for a while with this, the problem i have is the following:

I have a page that you navigate to after selecting to up-sell a product, this then in turn creates a spinner (on the new page) that populates that products that you can choose, once a product is selected, i navigate to another page, where you can take photos off the signed documents that go with the product.

But what happens is, when i select a product, and select t continue to the next page so that i may take multiple photos, and upload them with descriptions ( they cannot be uploaded without a description [comment] ) my page starts to load, i can see the name of the page that i have given it, and then it stops, displaying only a blank screen and the header name, then it does a post back to the previous screen, and i have no idea why

i will start by showing you my code for the screen where you choose the products, the code behind:

Code Behind

namespace CFCCR
{
[Activity(Label = "Merchandise")]
public class Conduct_Stock : Activity
{
private ProgressDialog oProgressDialog;
string sDate;
Validate ovalidate = new Validate();
string sQUERY = "";
string sOutlet = "";
string sNameSurname = "";
List lstStockItems = new List();
List lstStockInsert = new List();
Dictionary<String, long> dicStockItems = new Dictionary<String, long>();
string sRSP = "";
string sStock = "";
long lStock_ID = 0;
long lEmployee_ID = 0;
long lSurvey_ID = 0;
long lProducts_ID = 0;
long lProject_ID = 0;
long lCycle_ID = 0;
long lChain_ID = 0;
string sQuantity, sDamagedStock, sOutletSellingPrice;
long lSites_ID = 0;
string sDefaultorientation = "";
string sStockHoldinRequired = "";
TextView lblMessage;
string sUsername = "";
string sPassword = "";

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Conduct_Stock);
        this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
        Log.Debug("sStock loaded", "=true");
        View title = (View)Window.FindViewById(Android.Resource.Id.Title);
        FrameLayout titlebar = (FrameLayout)title.Parent;
        TextView txt = (TextView)titlebar.GetChildAt(0);
        txt.Gravity = GravityFlags.Center;
        Database.Generic oGeneric = new Database.Generic(this);
        Database.Login oLogin = new Database.Login(this);
        Database.Sites oSites = new Database.Sites(this);
        Database.Global oGlobals = new Database.Global(this);
        sQUERY = "SELECT lEmployee_ID FROM tblEmployee";
        lEmployee_ID = oLogin.GetLongValue(sQUERY);
        sQUERY = "SELECT lProject_ID FROM tblProject where sstatus='active'";
        lProject_ID = oGeneric.GetLongValue(sQUERY);
        sQUERY = "SELECT lCycle_ID FROM tblCycle where sstatus='active'";
        lCycle_ID = oGeneric.GetLongValue(sQUERY);
        sQUERY = "SELECT lSurvey_ID FROM tblSurveyConducted";
        lSurvey_ID = oGlobals.GetLongValue(sQUERY);
        Log.Debug("lSurvey_ID stock conduct", Convert.ToString(lSurvey_ID));
        sQUERY = "SELECT lSites_ID FROM tblSurveyConducted";
        lSites_ID = oGlobals.GetLongValue(sQUERY);
        Log.Debug("lSites_ID stock conduct", Convert.ToString(lSites_ID));

        GetStock();
        Spinner cboStock = FindViewById<Spinner>(Resource.Id.cboStock);
        cboStock.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(cboStock_ItemSelected);
        ArrayAdapter<String> adaptercboStock = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleSpinnerItem, lstStockItems);
        adaptercboStock.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
        cboStock.Adapter = adaptercboStock;
            sDate = ovalidate.GetTodayDate();
            sQUERY = "SELECT sSite FROM tblSites WHERE lSites_ID = " + lSites_ID;
            sOutlet = oSites.GetStringValue(sQUERY);
        sQUERY = "SELECT DISTINCT sMerchandise FROM tblMerchandise ORDER By sMerchandise";
            if (oSites.RecordExists(sQUERY) == true)
            {
                sQUERY = "SELECT  * FROM tblSurveyMerchandise WHERE lSites_ID=" + lSites_ID + " AND sDate = '" + sDate + "'";

                if (oSites.RecordExists(sQUERY) == false)
                {
                sQUERY = "SELECT sMerchandise,lMerchandise_ID FROM tblMerchandise ";
                    if (oSites.RecordExists(sQUERY) == true)
                    {
                        var cursorStock = oSites.ReadableDatabase.RawQuery(sQUERY, null);
                        if (cursorStock.Count > 0)
                        {
                            while (cursorStock.MoveToNext())
                            {
                                try
                                {
                                    string sRSPToAdd = "";//cursorStock.GetString(0);
                                    string sStockToAdd = cursorStock.GetString(1);
                                    long lStock_IDToAdd = cursorStock.GetLong(2);
                                    sQUERY = "SELECT lSurveyMerchandise_ID FROM tblSurveyMerchandise WHERE lSurvey_ID  = " + lSurvey_ID + " AND lSurveyMerchandise_ID = " + lStock_IDToAdd;

                                    if (oSites.RecordExists(sQUERY) == false)
                                    {
                                        lstStockInsert.Add("INSERT INTO tblSurveyMerchandise(lSurvey_ID,lEmployee_ID,sDate,lSites_ID,lMerchandise_ID,sSiteSellingPrice,sRSP,sSite,sMerchandise,sNameSurname,sQuantity,sDamagedStock)" + " VALUES (" + lSurvey_ID + "," + lEmployee_ID + ",'" + sDate + "'," + lSites_ID + "," + lStock_IDToAdd + ",'" + sOutletSellingPrice + "','" + sRSPToAdd + "','" + sOutlet + "','" + sStockToAdd + "','" + sNameSurname + "','" + sQuantity + "', '" + sDamagedStock + "');");

                                    }
                                }
                                catch (Exception) { }
                            }
                            if (lstStockInsert.Count > 0)
                            {
                                foreach (string query in lstStockInsert)
                                {
                                    oSites.ExecuteNonQuery(query);                                   
                                }
                            }
                        }
                        cursorStock.Deactivate();
                    }
                }

            }
            ImageButton cmdView = FindViewById<ImageButton>(Resource.Id.cmdView);
            ImageButton cmdSetComplete = FindViewById<ImageButton>(Resource.Id.cmdSetComplete);
            ImageButton cmdHome = FindViewById<ImageButton>(Resource.Id.cmdHome);
            cmdHome.Click += (sender, e) =>
            {
                var intSurveyDetails = new Intent(this, typeof(Survey_Details));
                StartActivity(intSurveyDetails);
            };
            cmdSetComplete.Click += (sender, e) =>
            {
                //mark stock as complete
                sQUERY = "delete from tblSiteRequirements where sRequirement='Stock'";
                oGlobals.ExecuteNonQuery(sQUERY);
                var intSurvey_Details = new Intent(this, typeof(Survey_Details));
                StartActivity(intSurvey_Details);
            };
            cmdView.Click += (sender, e) =>
            {  
                    var intentSaveStock = new Intent(this, typeof(Stock_Save));
                    intentSaveStock.PutExtra("lSurvey_ID ", lSurvey_ID );
                    intentSaveStock.PutExtra("sStockItem", sStock);
                    intentSaveStock.PutExtra("lSites_ID", lSites_ID);   
                    StartActivity(intentSaveStock);
                };
      }
        private void GetStock()
        {
            Database.Sites oSites = new Database.Sites(this);
            sQUERY = "SELECT sMerchandise,lMerchandise_ID FROM tblMerchandise ORDER By sMerchandise Asc";
          Log.Debug("stock-query", sQUERY);
            var cursor = oSites.ReadableDatabase.RawQuery(sQUERY, null);
            string sStockItem = "";
            if (cursor.Count > 0)
            {
                while (cursor.MoveToNext())
                {
                    try
                    {
                        sStockItem = cursor.GetString(0);
                        if (!String.IsNullOrEmpty(sStockItem))
                        {
                            if (!lstStockItems.Contains(sStockItem))
                            {
                                lstStockItems.Add(sStockItem);
                                if (!(dicStockItems.ContainsKey(sStockItem)))
                                {
                                    dicStockItems.Add(sStockItem, cursor.GetLong(1));
                                }
                            }
                        }
                    }
                    catch (Exception e) { }
                }
            }
            cursor.Deactivate();
        }
        private void cboStock_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            Spinner cboStock = (Spinner)sender;
            sStock = (string)cboStock.GetItemAtPosition(e.Position);
            lStock_ID = dicStockItems[sStock];
        }
    }
}

** this is the page that does the load for my products in a spinner, and then the goal is to go to the next screen on the view click, and pass the id of the selected item in the spinner, so that i know which product needs the documentation.(Photos) that i am going to upload.
I will now show the code behind for the screen where i am navigating to, this is the screen that just pops up, goes blank and redirects back to the page before the one mentioned above:
pd i have the same using inheritance at the top of all my screens **
//
namespace CFCCR
{
[Activity(Label = "Upsell")]
public class Stock_Save : Activity
{
Validate oVALIDATE = new Validate();
string sQUERY;
TextView lblMessage;
long lProject_ID = 0;
long lCycle_ID = 0;
Java.IO.File sfile = null;
private readonly static int TakePicture = 1;
private readonly static int SelectPicture = 2;
private string imageUriString = "";
string sComment = "";
string datePictureTaken = "";
string sDescription = "";
long lEmployee_ID = 0;
EditText txtComment;
TextView lblComment;
long lSurvey_ID = 0;
long lSurveyQuestion_ID = 0;
long lSites_ID = 0;
long lSurveyType_ID = 0;
long lProducts_ID = 0;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.Photographs);
        this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
        View title = (View)Window.FindViewById(Android.Resource.Id.Title);
        FrameLayout titlebar = (FrameLayout)title.Parent;
        TextView txt = (TextView)titlebar.GetChildAt(0);
        //txt.SetGravity(Gravity.CENTER);
        txt.Gravity = GravityFlags.Center;
        Database.Generic oGeneric = new Database.Generic(this);
        Database.Login oLogin = new Database.Login(this);
        Database.Sites oSites = new Database.Sites(this);
        Database.Global oGlobals = new Database.Global(this);
        sQUERY = "SELECT lEmployee_ID FROM tblEmployee";
        lEmployee_ID = oLogin.GetLongValue(sQUERY);
        sQUERY = "SELECT lProject_ID FROM tblProject   where sstatus='active'";
        lProject_ID = oGeneric.GetLongValue(sQUERY);
        sQUERY = "SELECT lCycle_ID FROM tblCycle where sstatus='active'";
        lCycle_ID = oGeneric.GetLongValue(sQUERY);
        lSurveyQuestion_ID = Intent.GetLongExtra("lSurveyQuestion_ID", -1);
        imageUriString = Intent.GetStringExtra("ImageUri");
        TextView lblObjective = FindViewById<TextView>(Resource.Id.lblObjective);
        lblMessage = FindViewById<TextView>(Resource.Id.lblMessage);
        TextView lblFilePath = FindViewById<TextView>(Resource.Id.lblFilePath);
        txtComment = FindViewById<EditText>(Resource.Id.txtComment);
        lblFilePath.Text = imageUriString;
        sQUERY = "SELECT lSurveyType_ID FROM tblSurveyTypeConducted";
        lSurveyType_ID = oGlobals.GetLongValue(sQUERY);
        sQUERY = "SELECT lSurvey_ID FROM tblSurveyConducted";
        lSurvey_ID = oGlobals.GetLongValue(sQUERY);
        sQUERY = "SELECT lSites_ID FROM tblSurveyConducted";
        lSites_ID = oGlobals.GetLongValue(sQUERY);
        sQUERY = "SELECT lStock_ID FROM tblSurveyMerchandise";
        lProducts_ID = oGlobals.GetLongValue(sQUERY);
        try
        {
            sQUERY = "SELECT sSurveyQuestion FROM tblSurveyQuestion WHERE lSurveyQuestion_ID = " + lSurveyQuestion_ID;
            lblObjective.Text = oSites.GetStringValue(sQUERY);     
        }
        catch (Exception)
        {
        }
        ImageButton cmdOpenCamera = FindViewById<ImageButton>(Resource.Id.cmdOpenCamera);
        ImageButton cmdSave = FindViewById<ImageButton>(Resource.Id.cmdSave);
        ImageButton cmdGallery = FindViewById<ImageButton>(Resource.Id.cmdOpenGallery);
        ImageButton cmdSetComplete = FindViewById<ImageButton>(Resource.Id.cmdSetComplete);
        ImageButton cmdHome = FindViewById<ImageButton>(Resource.Id.cmdHome);
        string sComment = txtComment.Text;
        if (txtComment.Text.Length > 0)
        {
            sDescription = oVALIDATE.FixForSQL(sComment);
        }
        else
        {
            sDescription = oVALIDATE.FixForSQL(sComment);
        }
        cmdHome.Click += (sender, e) =>
        {
            var FMEhome = new Intent(this, typeof(MainMenu));
            StartActivity(FMEhome);
        };
        cmdOpenCamera.Click += (sender, e) =>
        {
            var intent = new Intent(MediaStore.ActionImageCapture);
            var availableActivities = this.PackageManager.QueryIntentActivities(intent, Android.Content.PM.PackageInfoFlags.MatchDefaultOnly);
            Random rnd = new Random(DateTime.Now.Second + DateTime.Now.Millisecond);
            long uniqueId = rnd.Next() ;
            string filePath = Convert.ToString(uniqueId) + ".jpg";
            if (availableActivities != null && availableActivities.Count > 0)
            {
                var dir = new Java.IO.File(
                    Android.OS.Environment.GetExternalStoragePublicDirectory(
                        Android.OS.Environment.DirectoryPictures), "CFSR/" + DateTime.Now.Year + "/" + DateTime.Now.ToString("MMMM") + "/CF_Photos/");
                if (!dir.Exists())
                {
                    dir.Mkdirs();
                }
                //project_Diaryid_calltypeanswerID
                sfile = new Java.IO.File(dir, filePath);
                intent.PutExtra(MediaStore.ExtraOutput,
                Android.Net.Uri.FromFile(sfile));
                StartActivityForResult(intent, TakePicture);
            }
        };
        cmdGallery.Click += (sender, e) =>
        {
            Intent intent = new Intent();
            intent.SetType("image/*");
            intent.SetAction(Intent.ActionGetContent);
            StartActivityForResult(Intent.CreateChooser(intent,
                "Select Picture"), SelectPicture);
        };
        cmdSave.Click += (sender, e) =>
        {


if(!(String.IsNullOrEmpty(sComment)))
{
if(!(String.IsNullOrEmpty(imageUriString)))
{
sQUERY = "INSERT INTO tblProductSigned_Docs (lOutlet_ID,lProduct_ID,sComment,sPhoto_Uri) VALUES (" + lSites_ID + "," + lProducts_ID + ",'" + sDescription + "','" + imageUriString + "')";
oSites.ExecuteNonQuery(sQUERY);
lblFilePath.Text = "";
}
else{
lblMessage.Text = "Please provide a photo.";
}
}else{
lblMessage.Text = "Please provide a Comment.";
}
};
cmdSetComplete.Click += (sender, e) =>
{
sQUERY = "delete from tblSiteRequirements where sRequirement='Pos'";
oGlobals.ExecuteNonQuery(sQUERY);
var intentConduct = new Intent(this, typeof(DiaryConduct));
intentConduct.PutExtra("lSurvey_ID ", lSurvey_ID );
StartActivity(intentConduct);
};
}
protected override void OnActivityResult(int requestCode, Result resultCode,
Android.Content.Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok && requestCode == TakePicture)
{
var mediaScanIntent =
new Intent(Intent.ActionMediaScannerScanFile);
var contentUri = Android.Net.Uri.FromFile(sfile);

            this.SendBroadcast(mediaScanIntent);
            var uploadIntent = new Intent(this.BaseContext, typeof(Photographs));
            uploadIntent.PutExtra("ImageUri", contentUri.Path);               
            uploadIntent.PutExtra("lSurvey_ID ", lSurvey_ID );
            uploadIntent.PutExtra("lSurveyQuestion_ID", lSurveyQuestion_ID);
            this.StartActivity(uploadIntent);
        }
        if (resultCode == Result.Ok && requestCode == SelectPicture)
        {
            string imagePath;
            Android.Net.Uri contentUri = Android.Net.Uri.Parse(data.DataString);
            imagePath = getPath(contentUri);
            var uploadIntent = new Intent(this.BaseContext, typeof(Photographs));
            uploadIntent.PutExtra("ImageUri", imagePath);
            uploadIntent.PutExtra("lSurvey_ID ", lSurvey_ID );
            uploadIntent.PutExtra("lSurveyQuestion_ID", lSurveyQuestion_ID);
            this.StartActivity(uploadIntent);
        }
    }
    public String getPath(Android.Net.Uri uri)
    {
        String[] projection = { MediaStore.Images.ImageColumns.Data };
        var cursor = MediaStore.Images.Media.Query(ContentResolver, uri, projection);
        int column_index = cursor
        .GetColumnIndexOrThrow(MediaStore.Images.ImageColumns.Data);
        cursor.MoveToFirst();
        return cursor.GetString(column_index);
    }
}

}
the goal is for this page to load with the products id in mind and then take a photo, save it with a description (Comment) and then it should give you the option to take another photo, until you state that it is enough (marked Complete - cmdSetComplete) then and only then should it return you to the previous screen mentioned first, and there give you the option to select another product ect.

I know this is a tough question, so i hope there is someone out there who can help me resolve this, my deadline is so close that its scary

thank you in advance

Sign In or Register to comment.