I am developing an app in which I want to use transliteration from Hindi to English via speech input. for that, I am using google STT API. Everything works when my voice input is short, but when I give long voice input, Dialog gets stuck at "Try Saying Something..." and I don't get results a well.
This is my Main Activity:-
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
// Record Button
AppCompatButton RecordBtn;
// TextView to show Original and recognized Text
TextView Original,result;
// Request Code for STT
private final int SST_REQUEST_CODE = 101;
// Conversion Table Object...
ConversionTable conversionTable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Original = findViewById(R.id.Original_Text);
RecordBtn = findViewById(R.id.RecordBtn);
result = findViewById(R.id.Recognized_Text);
RecordBtn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.RecordBtn:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// For 30 Sec it will Record...
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 30);
// Use Off line Recognition Engine only...
intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, false);
// Use Hindi Speech Recognition Model...
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN");
try {
startActivityForResult(intent, SST_REQUEST_CODE);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.error),
Toast.LENGTH_SHORT).show();
}
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SST_REQUEST_CODE:
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> getResult = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Original.setText(getResult.get(0));
conversionTable = new ConversionTable();
String Transformed_String = conversionTable.transform(getResult.get(0));
result.setText(Transformed_String);
}
break;
}
}
}
My ConversationTable.class :-
package android.example.com.conversion;
import android.util.Log;
import java.util.ArrayList;
import java.util.Hashtable;
public class ConversionTable
{
private String TAG = "Conversation Table";
private Hashtable<String,String> unicode;
private void populateHashTable()
{
unicode = new Hashtable<>();
// unicode
unicode.put("\u0901","rha"); // anunAsika - cchandra bindu, using ~ to // *
unicode.put("\u0902","n"); // anusvara
unicode.put("\u0903","ah"); // visarga
unicode.put("\u0940","ee");
unicode.put("\u0941","u");
unicode.put("\u0942","oo");
unicode.put("\u0943","rhi");
unicode.put("\u0944","rhee"); // * = Doubtful Case
unicode.put("\u0945","e");
unicode.put("\u0946","e");
unicode.put("\u0947","e");
unicode.put("\u0948","ai");
unicode.put("\u0949","o");
unicode.put("\u094a","o");
unicode.put("\u094b","o");
unicode.put("\u094c","au");
unicode.put("\u094d","");
unicode.put("\u0950","om");
unicode.put("\u0958","k");
unicode.put("\u0959","kh");
unicode.put("\u095a","gh");
unicode.put("\u095b","z");
unicode.put("\u095c","dh"); // *
unicode.put("\u095d","rh");
unicode.put("\u095e","f");
unicode.put("\u095f","y");
unicode.put("\u0960","ri");
unicode.put("\u0961","lri");
unicode.put("\u0962","lr"); // *
unicode.put("\u0963","lree"); // *
unicode.put("\u093E","aa");
unicode.put("\u093F","i");
// Vowels and Consonants...
unicode.put("\u0905","a");
unicode.put("\u0906","a");
unicode.put("\u0907","i");
unicode.put("\u0908","ee");
unicode.put("\u0909","u");
unicode.put("\u090a","oo");
unicode.put("\u090b","ri");
unicode.put("\u090c","lri"); // *
unicode.put("\u090d","e"); // *
unicode.put("\u090e","e"); // *
unicode.put("\u090f","e");
unicode.put("\u0910","ai");
unicode.put("\u0911","o");
unicode.put("\u0912","o");
unicode.put("\u0913","o");
unicode.put("\u0914","au");
unicode.put("\u0915","k");
unicode.put("\u0916","kh");
unicode.put("\u0917","g");
unicode.put("\u0918","gh");
unicode.put("\u0919","ng");
unicode.put("\u091a","ch");
unicode.put("\u091b","chh");
unicode.put("\u091c","j");
unicode.put("\u091d","jh");
unicode.put("\u091e","ny");
unicode.put("\u091f","t"); // Ta as in Tom
unicode.put("\u0920","th");
unicode.put("\u0921","d"); // Da as in David
unicode.put("\u0922","dh");
unicode.put("\u0923","n");
unicode.put("\u0924","t"); // ta as in tamasha
unicode.put("\u0925","th"); // tha as in thanks
unicode.put("\u0926","d"); // da as in darvaaza
unicode.put("\u0927","dh"); // dha as in dhanusha
unicode.put("\u0928","n");
unicode.put("\u0929","nn");
unicode.put("\u092a","p");
unicode.put("\u092b","ph");
unicode.put("\u092c","b");
unicode.put("\u092d","bh");
unicode.put("\u092e","m");
unicode.put("\u092f","y");
unicode.put("\u0930","r");
unicode.put("\u0931","rr");
unicode.put("\u0932","l");
unicode.put("\u0933","ll"); // the Marathi and Vedic 'L'
unicode.put("\u0934","lll"); // the Marathi and Vedic 'L'
unicode.put("\u0935","v");
unicode.put("\u0936","sh");
unicode.put("\u0937","ss");
unicode.put("\u0938","s");
unicode.put("\u0939","h");
// represent it\
// unicode.put("\u093c","'"); // avagraha using "'"
// unicode.put("\u093d","'"); // avagraha using "'"
unicode.put("\u0969","3"); // 3 equals to pluta
unicode.put("\u014F","Z");// Z equals to upadhamaniya
unicode.put("\u0CF1","V");// V equals to jihvamuliya....but what character have u settled for jihvamuliya
/* unicode.put("\u0950","Ω"); // aum
unicode.put("\u0958","κ"); // Urdu qaif
unicode.put("\u0959","Κ"); //Urdu qhe
unicode.put("\u095A","γ"); // Urdu gain
unicode.put("\u095B","ζ"); //Urdu zal, ze, zoe
unicode.put("\u095E","φ"); // Urdu f
unicode.put("\u095C","δ"); // Hindi 'dh' as in padh
unicode.put("\u095D","Δ"); // hindi dhh*/
unicode.put("\u0926\u093C","τ"); // Urdu dwad
unicode.put("\u0924\u093C","θ"); // Urdu toe
unicode.put("\u0938\u093C","σ"); // Urdu swad, se
}
ConversionTable()
{
populateHashTable();
}
public String transform(String s1)
{
StringBuilder transformed = new StringBuilder();
int strLen = s1.length();
ArrayList<String> shabda = new ArrayList<>();
String lastEntry = "";
for (int i = 0; i < strLen; i++)
{
char c = s1.charAt(i);
String varna = String.valueOf(c);
Log.d(TAG, "transform: " + varna + "\n");
String halant = "0x0951";
if (VowelUtil.isConsonant(varna))
{
Log.d(TAG, "transform: " + unicode.get(varna));
shabda.add(unicode.get(varna));
shabda.add(halant); //halant
lastEntry = halant;
}
else if (VowelUtil.isVowel(varna))
{
Log.d(TAG, "transform: " + "Vowel Detected...");
if (halant.equals(lastEntry))
{
if (varna.equals("a"))
{
shabda.set(shabda.size() - 1,"");
}
else
{
shabda.set(shabda.size() - 1, unicode.get(varna));
}
}
else
{
shabda.add(unicode.get(varna));
}
lastEntry = unicode.get(varna);
} // end of else if is-Vowel
else if (unicode.containsKey(varna))
{
shabda.add(unicode.get(varna));
lastEntry = unicode.get(varna);
}
else
{
shabda.add(varna);
lastEntry = varna;
}
} // end of for
for (String string: shabda)
{
transformed.append(string);
}
//Discard the shabda array
shabda = null;
return transformed.toString(); // return transformed;
}
}
My ViewUtil Class:-
package android.example.com.conversion;
public class VowelUtil {
protected static boolean isVowel(String strVowel) {
// Log.logInfo("came in is_Vowel: Checking whether string is a Vowel");
return strVowel.equals("a") || strVowel.equals("aa") || strVowel.equals("i") || strVowel.equals("ee") ||
strVowel.equals("u") || strVowel.equals("oo") || strVowel.equals("ri") || strVowel.equals("lri") || strVowel.equals("e")
|| strVowel.equals("ai") || strVowel.equals("o") || strVowel.equals("au") || strVowel.equals("om");
}
protected static boolean isConsonant(String strConsonant) {
// Log.logInfo("came in is_consonant: Checking whether string is a
// consonant");
return strConsonant.equals("k") || strConsonant.equals("kh") || strConsonant.equals("g")
|| strConsonant.equals("gh") || strConsonant.equals("ng") || strConsonant.equals("ch") || strConsonant.equals("chh") || strConsonant.equals("j")
|| strConsonant.equals("jh") || strConsonant.equals("ny") || strConsonant.equals("t") || strConsonant.equals("th") ||
strConsonant.equals("d") || strConsonant.equals("dh") || strConsonant.equals("n") || strConsonant.equals("nn") || strConsonant.equals("p") ||
strConsonant.equals("ph") || strConsonant.equals("b") || strConsonant.equals("bh") || strConsonant.equals("m") || strConsonant.equals("y") ||
strConsonant.equals("r") || strConsonant.equals("rr") || strConsonant.equals("l") || strConsonant.equals("ll") || strConsonant.equals("lll") ||
strConsonant.equals("v") || strConsonant.equals("sh") || strConsonant.equals("ss") || strConsonant.equals("s") || strConsonant.equals("h") ||
strConsonant.equals("3") || strConsonant.equals("z") || strConsonant.equals("v") || strConsonant.equals("Ω") ||
strConsonant.equals("κ") || strConsonant.equals("K") || strConsonant.equals("γ") || strConsonant.equals("ζ") || strConsonant.equals("φ") ||
strConsonant.equals("δ") || strConsonant.equals("Δ") || strConsonant.equals("τ") || strConsonant.equals("θ") || strConsonant.equals("σ");
}
}
Outputs :-
for Short voice input :-
for Long voice Input, it stuck and can't get the result:-
The Problem is in Google's Implementation. I was facing the same type of difficulty and tried all the things, but did not work on anything.
So, i went on another way to solve this problem and the solution is implementing listeners by yourself. Here is my code for the same, it never popup the Inbuilt dialog (You can implement your custom dialog), but it works like charm.
Here is how you can do it :
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
// Record Button
AppCompatButton RecordBtn;
// TextView to show Original
TextView Original;
// SpeechRecognizer Object...
private SpeechRecognizer speechRecognizer;
// For TAG
private String TAG = getClass().getName();
// RecognizerIntent
private Intent recognizerIntent;
// Request Code for Permission
private static final int REQUEST_CODE_RECORD_AUDIO = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Original = findViewById(R.id.Original_Text);
RecordBtn = findViewById(R.id.RecordBtn);
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, R.string.record);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, false);
}
// For 30 Sec it will Record...
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 30);
// Use Hindi Speech Recognition Model...
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN");
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
// Permission Dialog
Askpermission();
RecordBtn.setOnClickListener(this);
}
private void Askpermission() {
// No explanation needed; request the permission
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECORD_AUDIO},
REQUEST_CODE_RECORD_AUDIO);
}
#Override
public void onRequestPermissionsResult(int requestCode,
#NonNull String permissions[], #NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_RECORD_AUDIO: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Operation();
} else {
Toast.makeText(MainActivity.this, "Permission denied to read your External storage", Toast.LENGTH_SHORT).show();
}
}
}
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.RecordBtn:
Log.d(TAG, "onClick: ");
if (checkPermission()) {
if (IsAvailable(this)) {
Log.d(TAG, "Speech Recognition Service Available...");
speechRecognizer.startListening(recognizerIntent);
} else {
Toast.makeText(this, "Speech Recognition Service not Available on your device...",
Toast.LENGTH_SHORT)
.show();
}
} else {
Askpermission();
}
break;
}
}
// Check if Speech recognition Service is Available on the Smartphone...
private boolean IsAvailable(Context context) {
return SpeechRecognizer.isRecognitionAvailable(context);
}
#Override
protected void onDestroy() {
super.onDestroy();
speechRecognizer.destroy();
}
// Check Audio Permission
private boolean checkPermission() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) ==
PackageManager.PERMISSION_GRANTED;
}
// Start Operation
private void Operation() {
speechRecognizer.setRecognitionListener(new RecognitionListener() {
#Override
public void onReadyForSpeech(Bundle params) {
Log.d(TAG, "Audio Service is connected to Servers....");
Log.d(TAG, "You can now start your speech...");
}
#Override
public void onBeginningOfSpeech() {
Log.d(TAG, "User has started speech...");
}
#Override
public void onRmsChanged(float rmsdB) {
}
#Override
public void onBufferReceived(byte[] buffer) {
}
#Override
public void onEndOfSpeech() {
Log.d(TAG, "User has Finished... speech...");
}
#Override
public void onError(int error) {
Log.d(TAG, "onError: " + error);
switch (error){
case SpeechRecognizer.ERROR_AUDIO:
Toast.makeText(MainActivity.this, "Error Recording Audio...", Toast
.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_CLIENT:
Toast.makeText(MainActivity.this, "Client Side Error...", Toast
.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
Toast.makeText(MainActivity.this, "Insufficient permissions...", Toast
.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_NETWORK:
Toast.makeText(MainActivity.this, "Network Related Error...", Toast
.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_NO_MATCH:
Toast.makeText(MainActivity.this, "Please Installed Offline Hindi " +
"Language Data...", Toast.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
Toast.makeText(MainActivity.this, "Recognition Busy...", Toast
.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_SERVER:
Toast.makeText(MainActivity.this, "Please Installed Offline Hindi " +
"Language Data...", Toast
.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
Toast.makeText(MainActivity.this, "Speech Timeout...", Toast
.LENGTH_SHORT).show();
break;
case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
Toast.makeText(MainActivity.this, "Network Timeout Error...", Toast
.LENGTH_SHORT).show();
}
}
#Override
public void onResults(Bundle results) {
ArrayList<String> Results = results.getStringArrayList(SpeechRecognizer
.RESULTS_RECOGNITION);
if (Results != null) {
Original.setText(Results.get(0));
}
}
#Override
public void onPartialResults(Bundle partialResults) {
}
#Override
public void onEvent(int eventType, Bundle params) {
}
});
}
}
I am able to Display Hint to the Spinner through the layout.I want to achieve the spinner field to be clear after the click in Submit button and should display hint. I am using spinner_district.setSelection(1); it is displaying the array of value 1 but i want to display hint not any value of spinner.
for clearing field
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
// spinner_district.setSelection(1);
function
public void onClick(View v) {
switch (v.getId()) {
case R.id.send_school_registration_form:
if (isConnected()) {
String name = registerSchoolName.getText().toString();
String address = registerSchoolAddress.getText().toString();
String phone = registerSchoolPhone.getText().toString();
String email = registerSchoolEmail.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-]+#[a-z]+\\.+[a-z]+";
String website = registerSchoolWebsite.getText().toString();
String estbdate = schoolEstDate.getText().toString();
String admissionOpen = schoolAdmissionStartDate.getText().toString();
String admissionEnd = schoolAdmissionEndDate.getText().toString();
district = null;
if (spinner_district != null && spinner_district.getSelectedItem() != null) {
district = (String) spinner_district.getSelectedItem();
}
country = null;
if (spinner_country != null && spinner_country.getSelectedItem() != null) {
country = (String) spinner_country.getSelectedItem();
}
institution = null;
if (spinner_institution != null && spinner_institution.getSelectedItem() != null) {
institution = (String) spinner_institution.getSelectedItem();
}
fee = registerSchoolFee.getText().toString();
level = null;
if (spinner_school_level != null && spinner_school_level.getSelectedItem() != null) {
level = (String) spinner_school_level.getSelectedItem();
}
if (addSchoolProgram1.getVisibility() == View.VISIBLE) {
fee1 = registerSchoolFee1.getText().toString();
level1 = null;
if (spinner_school_level1 != null && spinner_school_level1.getSelectedItem() != null) {
level1 = (String) spinner_school_level1.getSelectedItem();
}
}
if (addSchoolProgram2.getVisibility() == View.VISIBLE) {
fee2 = registerSchoolFee2.getText().toString();
level2 = null;
if (spinner_school_level2 != null && spinner_school_level2.getSelectedItem() != null) {
level2 = (String) spinner_school_level2.getSelectedItem();
}
}
if (addSchoolProgram3.getVisibility() == View.VISIBLE) {
fee3 = registerSchoolFee3.getText().toString();
level3 = null;
if (spinner_school_level3 != null && spinner_school_level3.getSelectedItem() != null) {
level3 = (String) spinner_school_level3.getSelectedItem();
}
}
if (addSchoolProgram4.getVisibility() == View.VISIBLE) {
fee4 = registerSchoolFee4.getText().toString();
level4 = null;
if (spinner_school_level4 != null && spinner_school_level4.getSelectedItem() != null) {
level4 = (String) spinner_school_level4.getSelectedItem();
}
}
if (addSchoolProgram5.getVisibility() == View.VISIBLE) {
fee5 = registerSchoolFee5.getText().toString();
level5 = null;
if (spinner_school_level5 != null && spinner_school_level5.getSelectedItem() != null) {
level5 = (String) spinner_school_level5.getSelectedItem();
}
}
if (addSchoolProgram6.getVisibility() == View.VISIBLE) {
fee6 = registerSchoolFee6.getText().toString();
level6 = null;
if (spinner_school_level6 != null && spinner_school_level6.getSelectedItem() != null) {
level6 = (String) spinner_school_level6.getSelectedItem();
}
}
if (addSchoolProgram7.getVisibility() == View.VISIBLE) {
fee7 = registerSchoolFee7.getText().toString();
level7 = null;
if (spinner_school_level7 != null && spinner_school_level7.getSelectedItem() != null) {
level7 = (String) spinner_school_level7.getSelectedItem();
}
}
if (addSchoolProgram8.getVisibility() == View.VISIBLE) {
fee8 = registerSchoolFee8.getText().toString();
level8 = null;
if (spinner_school_level8 != null && spinner_school_level8.getSelectedItem() != null) {
level8 = (String) spinner_school_level8.getSelectedItem();
}
}
if (addSchoolProgram9.getVisibility() == View.VISIBLE) {
fee9 = registerSchoolFee9.getText().toString();
level9 = null;
if (spinner_school_level9 != null && spinner_school_level9.getSelectedItem() != null) {
level9 = (String) spinner_school_level9.getSelectedItem();
}
}
if ((name.matches("")) || (address.matches("")) || (phone.matches("")) || (email.matches("")) || (website.matches("")) || (estbdate.matches("")) || (admissionOpen.matches(""))
|| (admissionEnd.matches("")) || (district.matches("")) || (country.matches("")) || (institution.matches("")) || (fee.matches("")) || (level.matches("")) ||
(schoolLogoUpload.getDrawable() == null)
) {
Toast.makeText(this, "Please fill up all the fields", Toast.LENGTH_LONG).show();
} else {
if ((email.matches(emailPattern)) && ((Patterns.WEB_URL.matcher(website)).matches())) {
Bitmap image = ((BitmapDrawable) schoolLogoUpload.getDrawable()).getBitmap();
new UploadImage(image, name, address, phone, email, website, district, country, institution, estbdate, fee, level, fee1, level1, fee2, level2, fee3, level3, fee4, level4, fee5, level5, fee6, level6, fee7, level7,
fee8, level8, fee9, level9, admissionOpen,
admissionEnd).execute();
} else
Toast.makeText(getApplicationContext(), "Invalid website and email address", Toast.LENGTH_LONG).show();
}
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
// spinner_district.setSelection(1);
//spinner_district.setSelection(1);
Spinner spinner_country, spinner_institution, spinner_school_level, spinner_school_level1, spinner_school_level2, spinner_school_level3, spinner_school_level4,
spinner_school_level5, spinner_school_level6, spinner_school_level7, spinner_school_level8, spinner_school_level9;
} else {
Toast.makeText(this, "Please check your internet connection", Toast.LENGTH_LONG).show();
}
break;
case R.id.cancel_school_registration_form:
this.finish();
break;
case R.id.register_school_logo:
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
break;
case R.id.register_school_estdate:
datePickerDialogSchool.show();
break;
case R.id.school_admission_startDate:
schoolAdmissionStartDatePicker.show();
break;
case R.id.school_admission_end_date:
schoolAdmissionEndDatePicker.show();
break;
case R.id.add_more_school_programs:
if (addMoreSchoolProgram.getVisibility() == View.VISIBLE) {
if (addSchoolProgram9.getVisibility() == View.GONE) {
if (addSchoolProgram8.getVisibility() == View.GONE) {
if (addSchoolProgram7.getVisibility() == View.GONE) {
if (addSchoolProgram6.getVisibility() == View.GONE) {
if (addSchoolProgram5.getVisibility() == View.GONE) {
if (addSchoolProgram4.getVisibility() == View.GONE) {
if (addSchoolProgram3.getVisibility() == View.GONE) {
if (addSchoolProgram2.getVisibility() == View.GONE) {
if (addSchoolProgram1.getVisibility() == View.GONE) {
addSchoolProgram1.setVisibility(View.VISIBLE);
} else
addSchoolProgram2.setVisibility(View.VISIBLE);
} else
addSchoolProgram3.setVisibility(View.VISIBLE);
} else
addSchoolProgram4.setVisibility(View.VISIBLE);
} else
addSchoolProgram5.setVisibility(View.VISIBLE);
} else
addSchoolProgram6.setVisibility(View.VISIBLE);
} else
addSchoolProgram7.setVisibility(View.VISIBLE);
} else
addSchoolProgram8.setVisibility(View.VISIBLE);
} else
addSchoolProgram9.setVisibility(View.VISIBLE);
} else
addMoreSchoolProgram.setVisibility(View.GONE);
}
break;
case R.id.register_school_email:
}
}
How can resetting to spinner be done with providing hint not the
spinner values??
you can use following code to solve the issue
admissionEnd).execute();
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
spinner_district.setSelection(0);
use setPrompt and setSelection
I have implemented recycler view in the following manner :
now on the click of any one of the rows, the view is expanded like this :
now the problem i am facing is that when i try to expand the last item of the recycler view , the view is expanded but we cannot understand as the recycler view does not scroll up. so it is expaned in real but since it is below the screen the user thinks that nothing has happened.
Like in the 1st image if we click on the last item, i.e. photograph the row is expanded but we donot understand untill we actually scroll it up like this :
so now how do i acheive this ? i mean if the last item on the screen is expanded how to i scroll it a bit up so the user understands the difference.
CODE :
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof ViewHolder)
{
final ViewHolder bodyholder = (ViewHolder) holder;
if (UtilInsta.PendingDoc.get(position).name.length() == 0) {
pd = new InstaDrawer();
bodyholder.penddoc_tv.setText(UtilInsta.PendingDoc.get(position).DOC_NAME);
if (UtilInsta.PendingDoc.get(position).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
} else {
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
bodyholder.pending_row.setId(position);
bodyholder.pending_row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// crop(position);
InstaDrawer.pendingDocList= UtilInsta.PendingDoc.get(v.getId());
UtilInsta.setPosition(con, v.getId());
if (bodyholder.pend_ll.getVisibility() == View.VISIBLE) {
UtilInsta.PendingDoc.get(v.getId()).option = false;
bodyholder.pend_ll.setVisibility(View.GONE);
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
if (bodyholder.remarks_layout.getVisibility() == View.VISIBLE) {
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(v.getId()).will_chek = false;
UtilInsta.PendingDoc.get(v.getId()).unable_chek = false;
}
} else {
bodyholder.pend_ll.setVisibility(View.VISIBLE);
// setHide(v.getId());
if (UtilInsta.PendingDoc.get(v.getId()).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
} else {
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
UtilInsta.PendingDoc.get(v.getId()).option = true;
if (UtilInsta.PendingDoc.get(v.getId()).MIN_DOC == "Y") {
bodyholder.provie_later.setVisibility(View.GONE);
bodyholder.unable_submit.setVisibility(View.GONE);
}
}
if(expandedpos>=0 && expandedpos!=v.getId())
{
int prev = expandedpos;
notifyItemChanged(prev);
}
expandedpos = v.getId();
}
});
// holder.acct_name_tv.setText(pendingDocLists.get(position).CUST_NAME);
bodyholder.camera.setId(position);
bodyholder.camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
InstaDrawer.pendingDocList= UtilInsta.PendingDoc.get(v.getId());
UtilInsta.setPosition(con, v.getId());
if (UtilInsta.PendingDoc.get(v.getId()).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
if (Util.isNetworkConnected(con))
DocumentInfo(0, v.getId());
else
Util.shownointernet(con);
}
else {
UtilInsta.setFILE_NAME(con, "");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
( con.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || con.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)){
ActivityCompat.requestPermissions(((Activity)con),
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, com.app.hdfc.Manifest.permission.CAMERA},
MyConstants.READ_EXTERNAL_STORAGE_PERMISSION_CAM);
}
else
{
if(UtilInsta.PendingDoc.get(v.getId()).DOC_NAME.equalsIgnoreCase("Photograph"))
{
Intent intent = new Intent(con, FrontCamera.class);
UtilInsta.CUST_NO = UtilInsta.PendingDoc.get(v.getId()).CUST_NO;
(con).startActivity(intent);
((Activity)con).finish();
}else {
Intent intent = new Intent(con, CroppingActivity.class);
intent.putExtra("camera_gallery", 0);
intent.putExtra("fromRecycler", true);
intent.putExtra("position", v.getId());
intent.putExtra("DOC_NAME", UtilInsta.PendingDoc.get(v.getId()).DOC_NAME);
UtilInsta.doc_name = UtilInsta.PendingDoc.get(v.getId()).DOC_NAME;
Log.d("Recycler", UtilInsta.doc_name);
intent.putExtra("CUST_NO", UtilInsta.PendingDoc.get(v.getId()).CUST_NO);
(con).startActivity(intent);
((Activity) con).finish();
}
}
}
}
});
bodyholder.gallery.setId(position);
bodyholder.gallery.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
InstaDrawer.pendingDocList= UtilInsta.PendingDoc.get(v.getId());
UtilInsta.setPosition(con, v.getId());
if (UtilInsta.PendingDoc.get(v.getId()).ADDININFO_FLAG.equalsIgnoreCase("Y"))
if(Util.isNetworkConnected(con))
DocumentInfo(1, v.getId());
else
Util.shownointernet(con);
else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
con.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(((Activity)con),
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MyConstants.READ_EXTERNAL_STORAGE_PERMISSION);
}
else {
UtilInsta.setFILE_NAME(con, "");
Intent intent = new Intent(con, CroppingActivity.class);
intent.putExtra("camera_gallery", 1);
intent.putExtra("fromRecycler", true);
intent.putExtra("position", v.getId());
intent.putExtra("DOC_NAME", UtilInsta.PendingDoc.get(v.getId()).DOC_NAME);
UtilInsta.doc_name = UtilInsta.PendingDoc.get(v.getId()).DOC_NAME;
Log.d("Recycler", UtilInsta.doc_name);
intent.putExtra("CUST_NO", UtilInsta.PendingDoc.get(v.getId()).CUST_NO);
(con).startActivity(intent);
((Activity) con).finish();
}
}
}
});
if (UtilInsta.PendingDoc.get(position).MIN_DOC.equalsIgnoreCase("Y")) {
bodyholder.provie_later.setVisibility(View.GONE);
bodyholder.unable_submit.setVisibility(View.GONE);
} else {
bodyholder.provie_later.setVisibility(View.VISIBLE);
bodyholder.unable_submit.setVisibility(View.VISIBLE);
}
bodyholder.provie_later.setId(position);
bodyholder.provie_later.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (remark == 1) {
remark = 0;
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(v.getId()).will_chek = false;
} else if (remark == 0 || remark == 2) {
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1_hover);
remark = 1;
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(v.getId()).will_chek = true;
}
}
});
bodyholder.unable_submit.setId(position);
bodyholder.unable_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (remark == 2) {
remark = 0;
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(v.getId()).unable_chek = false;
} else if (remark == 0 || remark == 1) {
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.unable_submit.setImageResource(R.drawable.circle2_hover);
remark = 2;
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(v.getId()).unable_chek = true;
}
}
});
bodyholder.tv_clickforkyc.setId(position);
bodyholder.tv_clickforkyc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (Util.isNetworkConnected(con))
DocumentInfo(2, v.getId()); // 2 for kyc list
else
Util.shownointernet(con);
}
});
bodyholder.remarks_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String remark_str = bodyholder.remarks_edittext.getText().toString().trim();
if (remark_str.equalsIgnoreCase("")) {
Toast.makeText(con, "Please enter some remark", Toast.LENGTH_LONG).show();
} else if (remark_str.length() > 100) {
Toast.makeText(con, "Please enter remark less than 100 characters", Toast.LENGTH_LONG).show();
} else {
//Toast.makeText(con, "Remark : " + remark + " Submitted", Toast.LENGTH_LONG).show();
String remarktype = "";
if (remark == 1) {
remarktype = "PROVIDE_LATER";
} else if (remark == 2) {
remarktype = "NOT_AVAILABLE";
}
Log.e("Remarktype", remarktype + "1 " + remark);
if(Util.isNetworkConnected(con)) {
uploddoc(remarktype, remark_str);
bodyholder.remarks_edittext.setText("");
}
else
Util.shownointernet(con);
bodyholder.remarks_layout.setVisibility(View.GONE);
bodyholder.pend_ll.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).option = false;
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
}
});
// if (!UtilInsta.PendingDoc.get(position).REMARKS.equalsIgnoreCase("")) {
// bodyholder.remarks_tv.setVisibility(View.VISIBLE);
// bodyholder.remarks_tv.setText("*Remark - " + UtilInsta.PendingDoc.get(position).REMARKS);
if (UtilInsta.PendingDoc.get(position).STATUS.equalsIgnoreCase("NOT_AVAILABLE")) {
bodyholder.remarks_tv.setVisibility(View.VISIBLE);
bodyholder.remarks_tv.setText("*Remark - " + UtilInsta.PendingDoc.get(position).REMARKS);
bodyholder.unable_submit.setImageResource(R.drawable.circle2_hover);
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_edittext.setText(UtilInsta.PendingDoc.get(position).REMARKS);
UtilInsta.PendingDoc.get(position).unable_chek =true;
} else if (UtilInsta.PendingDoc.get(position).STATUS.equalsIgnoreCase("PROVIDE_LATER")) {
bodyholder.remarks_tv.setVisibility(View.VISIBLE);
bodyholder.remarks_tv.setText("*Remark - " + UtilInsta.PendingDoc.get(position).REMARKS);
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1_hover);
bodyholder.remarks_edittext.setText(UtilInsta.PendingDoc.get(position).REMARKS);
UtilInsta.PendingDoc.get(position).will_chek =true;
}
else {
bodyholder.remarks_tv.setVisibility(View.GONE);
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_edittext.setText("");
}
bodyholder.pending_row.setVisibility(View.VISIBLE);
bodyholder.acct_name_tv.setVisibility(View.GONE);
if (UtilInsta.PendingDoc.get(position).unable_chek) {
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.unable_submit.setImageResource(R.drawable.circle2_hover);
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(position).unable_chek = true;
} else {
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).unable_chek = false;
}
if (UtilInsta.PendingDoc.get(position).will_chek) {
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1_hover);
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(position).will_chek = true;
} else {
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).will_chek = false;
}
if (UtilInsta.PendingDoc.get(position).option) {
bodyholder.pend_ll.setVisibility(View.VISIBLE);
if (UtilInsta.PendingDoc.get(position).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
} else {
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
UtilInsta.PendingDoc.get(position).option = true;
if (UtilInsta.PendingDoc.get(position).MIN_DOC == "Y") {
bodyholder.provie_later.setVisibility(View.GONE);
bodyholder.unable_submit.setVisibility(View.GONE);
}
} else {
bodyholder.pend_ll.setVisibility(View.GONE);
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
if (bodyholder.remarks_layout.getVisibility() == View.VISIBLE) {
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).will_chek = false;
UtilInsta.PendingDoc.get(position).unable_chek = false;
}
}
} else if (UtilInsta.PendingDoc.get(position).name.length() > 0) {
bodyholder.pending_row.setVisibility(View.GONE);
bodyholder.acct_name_tv.setVisibility(View.VISIBLE);
bodyholder.acct_name_tv.setText(UtilInsta.PendingDoc.get(position).name);
//continue comeback;
}
if(expandedpos == position)
{
bodyholder.pend_ll.setVisibility(View.VISIBLE);
if(UtilInsta.PendingDoc.get(position).option)
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
else
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}else
{
bodyholder.pend_ll.setVisibility(View.GONE);
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
}else if (holder instanceof FooterViewHoldrer){
FooterViewHoldrer footerViewHoldrer = (FooterViewHoldrer) holder;
if(UtilInsta.PendingDoc.size()==0)
{
footerViewHoldrer.empty_pendingdoc.setVisibility(View.VISIBLE);
footerViewHoldrer.pending_continue.setVisibility(View.GONE);
footerViewHoldrer.loan_sanctioned.setVisibility(View.GONE);
}
else
{
footerViewHoldrer.empty_pendingdoc.setVisibility(View.GONE);
footerViewHoldrer.pending_continue.setVisibility(View.VISIBLE);
footerViewHoldrer.loan_sanctioned.setVisibility(View.VISIBLE);
}
if(submit_activate)
{
footerViewHoldrer.pending_continue.setBackgroundResource(R.drawable.background_button);
}else
{
footerViewHoldrer.pending_continue.setBackgroundResource(R.color.myblack);
}
footerViewHoldrer.pending_continue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(submit_activate) {
// Toast.makeText(con,"Button Activated.",Toast.LENGTH_SHORT).show();
if(Util.isNetworkConnected(con))
new UpdateStep().execute();
else
Util.shownointernet(con);
}else
{
Toast.makeText(con,"Submit/Remark all Documents",Toast.LENGTH_SHORT).show();
}
}
});
}
}
Try This:
yourRecyclerView.scrollToPosition(position);
the variable position will be having the value of the expanded position.
I have a handler inside oncreate of an activity. It receives a value from handler.sendEmptyMessage.
handleMessage is fired and it reaches till the line where I try to update the textview as shown below:
mImageCountText.setText("" + mCountText);
But the text of textview never gets changed. What am I missing here?
Is there anything obvious that causes this issue?
Any help is much appreciated.
EDIT
Handler code
Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
final int what = msg.what;
if (what == Constants.HANDLER_APP_UPDATE) {
if (!UserHelper.isAppBuildVerionSameAsUpdate(HomeActivity.this)) {
updateNotificationAlert();
showAppUpdatePopUp();
}
} else if (what == Constants.HANDLER_COLLECTION_UPDATE) {
//TODO: Refresh collection
} else {
mCountText = what;
if (!Utils.isTablet()) {
if (mCountText == 0) {
mImageCountText.setVisibility(View.INVISIBLE);
} else {
mImageCountText.setVisibility(View.VISIBLE);
mImageCountText.setText("" + mCountText); // this does not work
}
} else {
if (mCountText == 0) {
mCollectionsFragment.refreshAfterUpload();
mCountTextForUplaod.setVisibility(View.INVISIBLE);
} else {
mCollectionsFragment.refreshAfterUpload();
mCountTextForUplaod.setVisibility(View.VISIBLE);
mCountTextForUplaod.setText("" + mCountText);
}
}
}
}
};
Onreceive from where value is sent
#Override
public void onReceive(final Context context, final Intent intent) {
Runnable runnable = new Runnable() {
public void run() {
if (intent.getAction() != null && intent.getAction().equals(Constants.BROADCAST_INTENT_FILTER)) {
boolean broadcastStatus = intent.getBooleanExtra(Constants.BROADCAST_DATA_STATUS, false);
String broadcastStatusMessage = intent.getStringExtra(Constants.BROADCAST_DATA_STATUS_MESAGE);
if (broadcastStatus) {
mCountText = PreferenceHelper.getFromPreference(context, Constants.RECENT_IMAGES_COUNT, 0);
handler.sendEmptyMessage(PreferenceHelper.getFromPreference(context, Constants.RECENT_IMAGES_COUNT, 0));
}
} else {
if (intent.getAction() != null && intent.getAction().equals(Constants.BROADCAST_ACTION_APP_UPDATE)) {
handler.sendEmptyMessage(Constants.HANDLER_APP_UPDATE);
} else if (intent.getAction() != null && intent.getAction().equals(Constants.BROADCAST_ACTION_COLLECTION_UPDATE)) {
handler.sendEmptyMessage(Constants.HANDLER_COLLECTION_UPDATE);
}
}
}
};
Thread mythread = new Thread(runnable);
mythread.start();
Your code is too complex. You don't need the handler and definitively not the thread. Thy it like this:
#Override
public void onReceive(final Context context, final Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Constants.BROADCAST_INTENT_FILTER)) {
boolean broadcastStatus = intent.getBooleanExtra(Constants.BROADCAST_DATA_STATUS, false);
String broadcastStatusMessage = intent.getStringExtra(Constants.BROADCAST_DATA_STATUS_MESAGE);
if (broadcastStatus) {
mCountText = PreferenceHelper.getFromPreference(context, Constants.RECENT_IMAGES_COUNT, 0);
if (mCountText == 0) {
mCollectionsFragment.refreshAfterUpload();
mCountTextForUplaod.setVisibility(View.INVISIBLE);
} else {
mCollectionsFragment.refreshAfterUpload();
mCountTextForUplaod.setVisibility(View.VISIBLE);
mCountTextForUplaod.setText("" + mCountText);
}
}
} else {
if (intent.getAction() != null && intent.getAction().equals(Constants.BROADCAST_ACTION_APP_UPDATE)) {
if (!UserHelper.isAppBuildVerionSameAsUpdate(HomeActivity.this)) {
updateNotificationAlert();
showAppUpdatePopUp();
}
} else if (intent.getAction() != null && intent.getAction().equals(Constants.BROADCAST_ACTION_COLLECTION_UPDATE)) {
// TODO
}
}
}
Hi all I am using a splash activity for first time or he is logged out from my app. But this appear frequently on Samsung galaxy S2. This my activity onCreate() method code
private static EditText serverIP = null;
String mMDCServerIP = "";
String skipSplashScreenStatus = null;
String mSplashScreenRunningStatus = null;
String mDeniedStatusFromServer = null;
public void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
/** Get the MDC IP **/
Log.d("splash","1111111111111111");
skipSplashScreenStatus = Config.getSetting(getApplicationContext(),"SPLASHSTATUS");
mSplashScreenRunningStatus = Config.getSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS");
mDeniedStatusFromServer = Config.getSetting(getApplicationContext(),"DENYSTATUS");
if(skipSplashScreenStatus == null || skipSplashScreenStatus.length() == 0)
{
Config.setSetting(getApplicationContext(),"DENYSTATUS","false");
}
/** If SPLASHSTATUS does not exist then store the SPLASHSTATUS as false**/
if(skipSplashScreenStatus == null || skipSplashScreenStatus.length() == 0)
{
Config.setSetting(getApplicationContext(),"SPLASHSTATUS","false");
}
if(mSplashScreenRunningStatus == null || mSplashScreenRunningStatus.length() == 0)
{
Config.setSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS","yes");
}
Log.d("splash","222222222222222222");
Log.d("splash","skipSplashScreenStatus : "+skipSplashScreenStatus);
skipSplashScreenStatus = Config.getSetting(getApplicationContext(),"SPLASHSTATUS");
if(skipSplashScreenStatus!= null && skipSplashScreenStatus.equalsIgnoreCase("yes"))
{
Log.d("splash","inside if condition");
skipSplashScreen();
}
else{
Log.d("splash","inside else condition");
setContentView(R.layout.splash_screen);
Log.d("SPLASH","33333333333333");
serverIP = (EditText) findViewById(R.id.splash_server_ip);
/** Get the MDC IP **/
mMDCServerIP = Config.getSetting(getApplicationContext(),"IPADDR");
/** If MDC IP does not exist then store the IP as 0.0.0.0**/
if(mMDCServerIP == null || mMDCServerIP.length() == 0)
{
Config.setSetting(getApplicationContext(),"IPADDR","0.0.0.0");
}
serverIP.setOnEditorActionListener(new EditText.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Config.setSetting(getApplicationContext(),"SPLASHSTATUS","yes");
Config.setSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS","no");
skipSplashScreen();
}}}}
Here is the code for skipSplashScreen();
private void skipSplashScreen()
{
try{
Log.d("splash","inside skipSplashScreen 111");
CommandHandler.mStopSendingKeepAlive = false;
Log.d("splash","inside skipSplashScreen 222");
startActivity(new Intent(getApplicationContext() ,SecondTest.class));
}
catch(Exception e)
{
Log.d("splash","Exception in skipSplashScreen 333");
Log.d("splash",e.getMessage());
}
}
Once i dig more into code it seems control is skipSplashScreen() method but not starting second activity. May i know what can be the reason.
Try this, when starting the activity, use Activity.this instead of getApplicationContext()
private void skipSplashScreen()
{
try{
Log.d("splash","inside skipSplashScreen 111");
CommandHandler.mStopSendingKeepAlive = false;
Log.d("splash","inside skipSplashScreen 222");
startActivity(new Intent(SplashScreen.this ,SecondTest.class));
}
catch(Exception e)
{
Log.d("splash","Exception in skipSplashScreen 333");
Log.d("splash",e.getMessage());
}
}