MainActivity.java
public class MainActivity extends AppCompatActivity {
LinearLayout llStats;
TextView txtPlayCount, txtEarned;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
llStats = (LinearLayout) findViewById(R.id.llStats);
txtPlayCount = (TextView) findViewById(R.id.txtNowPlaying);
txtEarned = (TextView) findViewById(R.id.txtEarned);
// layout background transparent
llStats.getBackground().setAlpha(150);
llStats.setVisibility(View.VISIBLE);
Intent i = getIntent();
String now_playing = i.getStringExtra("now_playing");
String earned = i.getStringExtra("earned");
// Diplaying the text
txtPlayCount.setText(now_playing);
txtEarned.setText(earned);
}
}
闪屏.Java
public class SplashScreen extends Activity {
String now_playing, earned;
//Splash screen Timeout
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_splash_screen);
new PrefetchData().execute();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_TIME_OUT);
/* FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});*/
}
private class PrefetchData extends AsyncTask<Void,Void,Void>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
JsonParser jsonParser=new JsonParser();
String json=jsonParser.getJSONFromUrl("http://api.androidhive.info/game/game_stats.json");
Log.e("Response is ", ">" + json);
if (json != null)
try
{
JSONObject jObj=new JSONObject(json).getJSONObject("game_stat");
now_playing = jObj.getString("now_playing");
earned = jObj.getString("earned");
Log.e("JSON", "> " + now_playing + earned);
}
catch (JSONException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Intent i = new Intent(SplashScreen.this, MainActivity.class);
i.putExtra("now_playing", now_playing);
i.putExtra("earned", earned);
startActivity(i);
// close this activity
finish();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
return true;
}
}
错误列表
02-02 12:27:07.983 1856-2006/com.google.android.googlequicksearchbox:search W/ErrorReporter: reportError [type: 211, code: 524300]: Error at processing input stream 02-02 12:27:07.984 1856-2006/com.google.android.googlequicksearchbox:search W/ErrorProcessor: onFatalError, processing error from engine(4)
com.google.android.apps.gsa.shared.speech.a.g: Error at processing input stream
at com.google.android.search.core.hotword.l.bsw(HotwordRecognitionRunner.java:166)
at com.google.android.search.core.hotword.l$1.run(HotwordRecognitionRunner.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.google.android.apps.gsa.shared.util.c.a.l$1.run(GsaThreadFactory.java:99)
Caused by: com.google.android.apps.gsa.shared.api.io.GsaIOException: Error code: 393237 | Error code: 393220 | AudioRecord failed to initialize.
at com.google.android.apps.gsa.speech.audio.Tee.pO(Tee.java:426)
at com.google.android.apps.gsa.speech.audio.Tee.k(Tee.java:309)
at com.google.android.apps.gsa.speech.audio.ad.read(Tee.java:503)
at java.io.InputStream.read(InputStream.java:162)
at com.google.android.apps.gsa.speech.audio.z.run(MultipleReaderAudioSource.java:206)
Caused by: com.google.android.apps.gsa.shared.api.io.GsaIOException: Error code: 393220 | AudioRecord failed to initialize.
at com.google.android.apps.gsa.speech.audio.v.aHv(MicrophoneInputStream.java:172)
at com.google.android.apps.gsa.speech.audio.v.read(MicrophoneInputStream.java:224)
at com.google.android.apps.gsa.shared.util.ai.a(IoUtils.java:149)
at com.google.android.apps.gsa.speech.audio.Tee.pO(Tee.java:422)
at com.google.android.apps.gsa.speech.audio.Tee.k(Tee.java:309)
at com.google.android.apps.gsa.speech.audio.ad.read(Tee.java:503)
at java.io.InputStream.read(InputStream.java:162)
at com.google.android.apps.gsa.speech.audio.z.run(MultipleReaderAudioSource.java:206) 02-02 12:27:07.984 1856-2010/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Stopping hotword detection. 02-02 12:27:07.985 1856-1856/com.google.android.googlequicksearchbox:search I/HotwordWorker: #onError(false)