android – When downloading the blockchain my application is become unusable, is there an issue with my code or am I using the BitcoinJ library incorrectly?

I am building a Bitcoin wallet with the BitcoinJ Library, after looking at the example of fetching a transaction that they have shown on their github it shows that you need to download the blockchain however.

When attempting to download the blockchain to view the balance of my wallet, it begins to lock up and become unusable. I have even tried downloading the blockchain in an async task like so, but still the app becomes completely unusable and the UI doesn’t even load. What am I missing? I thought that the download wouldn’t be that large as I am attempting to create an SPV wallet which from what I understand doesn’t download the entire blockchain, or is this something I need to configure seperately?

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
DownloadBlockchain().execute()
}

inner class DownloadBlockchain : AsyncTask<Void, Int, String>() {
override fun doInBackground(vararg p0: Void?): String {
Globals.peerGroup?.startAsync()
Globals.peerGroup?.downloadBlockChain()
return "complete"
}

override fun onPostExecute(result: String?) {
super.onPostExecute(result)
Globals.peerGroup?.stopAsync()
Globals.wallet?.saveToFile(Globals.walletFile)
}
}
}

Source link

Leave a Comment

Your email address will not be published.